Reputation: 41
I am trying to get a filter in a collection, but I get an error:
"code": 500, "error_msg": "Undefined variable: request"
This is my code where I have the error. The request works in any part of the code, but not here...
$filterKarateka = $karatekasInMarket ->filter(function($item) {
return $item->id == $request->id_karateka;
})->first();
Upvotes: 1
Views: 526
Reputation: 17805
You have to use
as in include variables that are out of scope of the callback. So it would be
filter(function ($item) use ($request){
Upvotes: 1