You can use use
to propagate $id in the closure scope:
function ($query) use($id)
سؤال
I have an issue with my code :
public function show($id) {
$campaign = Campaign::where(function ($query) {
$query->where('Status', '=', 'yes')
->orWhere('AppUserId', '=', Auth::user()->AppUserId);
})->where(function ($query) {
$query->where('CampaignId', '=', $id);
})->get()->toArray();
}
I am getting
Undefined variable: id
How can i get $id variable value inside the function here :
$query->where('CampaignId', '=', $id);
using dependency injection instead of a global variable?
Any help would be greatly appreciated!
المحلول
You can use use
to propagate $id in the closure scope:
function ($query) use($id)