murilo

Eloquent Where HAs

Posted 11 months ago by murilo

Hello , I have a question .

if I do like this , it works -


       $user = User::whereHas('UserInfo', function($q) {
            $q->where('name_user', 'John');
        })->first();

        dd($user);

BUT , I am trying to do this Dynamic , like this -

  $name = "John";
       $user = User::whereHas('UserInfo', function($q , $name) {
            $q->where('name_user', $name);
        })->first();

        dd($user);

It will not work , It will give me errors , does some one knows how could I make Dynamic like the second option ?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.