2 years ago

Eloquent Where HAs

Posted 2 years 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');


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

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


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.