Domanda

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!

È stato utile?

Soluzione

You can use use to propagate $id in the closure scope:

function ($query) use($id) 

See also this answer.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top