shinichirou ikebe
shinichirou ikebe

Reputation: 233

Laravel Spatie How to Eager load Role And Permissions at once based on user

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

Answers (1)

Mohammad Ravand
Mohammad Ravand

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

Related Questions