Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Attached is a screenshot of the error I am facing. I have the log show the value of the $team variable. What am I doing wrong?
function($query) use ($team)
You don't have access to parents variables from a closure, you need to explicitly send variables to the closure with use keyword
Add a comment
Use forget to use $team variable inside your closure. It must be function($query) use ($team)
$data = User::whereHas('roles' => function($query) use ($team) { $query->where('role_code', '=', $team) })->get();
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
function($query) use ($team)(string: 18) to import this variable into closure from parent scope