0

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!

Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
Obama
  • 2,586
  • 2
  • 30
  • 49

1 Answers1

0

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

function ($query) use($id) 

See also this answer.

Community
  • 1
  • 1
Mister Henson
  • 505
  • 4
  • 20