I'm trying to use a parameter that is passed through to resource controller action in Laravel 4 in a closure that is filtering a model collection, however I get the error below:
Undefined variable: slug
How can I pass through the $slug
parameter from the route through to the collection filter closure?
public function show($slug)
{
return Auth::user()->sessions->filter(function($session)
{
return $session->slug == $slug;
});
}
All I am trying to achieve is to return the session of the user that matches the given slug. I've tried something like this to no avail:
Auth::user()->sessions->whereSlug($slug);