Hi this is how my code looks like
$users = App\User::with(['links' => function ($query, $q) {
$query->where('link', 'like', '%$q%');
}])->get();
The Problem is im getting PHP warning: Missing argument 2 for {closure}() on line 1
If i Try to Remove it and change the %$q% to %iyuri305% which is the name of the link i get this Result
=> Illuminate\Database\Eloquent\Collection {#783
all: [
App\User {#801
username: "supervip",
links: Illuminate\Database\Eloquent\Collection {#813
all: [],
},
},
App\User {#809
username: "yuri",
links: Illuminate\Database\Eloquent\Collection {#811
all: [
App\Link {#753
link: "iyuri305",
},
],
},
},
],
}
I want to Achieve an Effect Where in It Only Return to Me a User With a Link of iyuri305.
And Passing an Argument of $q is the Only Way i Can think of , But it is giving me Error in php artisan tinker.
I havent Tried it Yet Using a View Where i Will Fetch a $q.
Any Comment? Am i Doing it Correct or Not to Achieve the Effect i Want ?