-
| This is not a feature request of a bug. My a lack of skill issue. I have a laravel API app, and its meant to take a GET ID and use that in a match to get the individual item from Mongo. All my static queries are working ok. My code is: My error is: If I change this  And if i do a  Can anyone see what I am doing wrong? | 
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
| Closures don't automatically capture the current scope, so you have two ways of fixing this. If using a long closure, make sure to bind any variables used within the closure with the  $page = Track::raw(
    function ($collection) use ($value) {
        return $collection->aggregate([['$match' => ['my_id' => $value ]]]);
    }
);Alternatively, use a short closure which automatically captures the local scope: $page = Track::raw(
    fn ($collection) => 
        $collection->aggregate([['$match' => ['my_id' => $value ]]])
);I'll assume that you changed the code for brevity in this issue, but for the sake of completeness I'll mention that the query you're running neither requires an  $page = Track::find('my_id', $value)->first(); | 
Beta Was this translation helpful? Give feedback.
-
| that was it, thank you.. your a champion.. I guess its a related question.. What is a long vs short closure? My google foo let me down in searching (I used short from the above). | 
Beta Was this translation helpful? Give feedback.
-
| The correct name for the feature would be Arrow Function, which is a more concise syntax for anonymous functions introduced in PHP 7.4. | 
Beta Was this translation helpful? Give feedback.
Closures don't automatically capture the current scope, so you have two ways of fixing this. If using a long closure, make sure to bind any variables used within the closure with the
usekeyword:Alternatively, use a short closure which automatically captures the local scope:
I'll assume that you changed the code for brevity in this issue, but for the sake of completeness I'll mention that the query you're running neither requir…