Reputation: 233
its possible to eager load role and permissions at once using with()? im doing like code bellow.but not working ,if any of you guys can suggest me an articles or ways to solve this will be helpfull
$user = User::with('roles','permissions')->when(request()->q, function($user) {
$user = $user->where('name', 'like', '%'. request()->q . '%');
})->latest()->paginate(20);
Upvotes: 0
Views: 1668
Reputation: 21
when we are using team=1, we have to use this function before any running query.
Route::get('/user-infos',function(){
setPermissionsTeamId(1);
$user = User::with('roles')->get();
return $user;
});
Upvotes: 0