MichalOravec4 years agoLevel 75ReplyReport Spam$shows = Show::upcoming()->with(['events' => function ($q) use ($reward) { $q->restrictDays($reward->ticket_restrictions); }])->get(); Docs: https://www.php.net/manual/en/functions.anonymous.php (Look for Example #3 Inheriting variables from the parent scope) Like Reply
tykus4 years agoLevel 104ReplyReport SpamIf you are using PHP 7.4 or above, you can use short Closures (so do not need to worry about variable scope within the Closure): $shows = Show::upcoming() ->with(['events' => fn ($q) => $q->restrictDays($reward->ticket_restrictions)]) ->get(); Like Reply