Get all the users except current logged in user in laravel eloquent

后端 未结 4 1982
无人共我
无人共我 2021-01-31 15:44

I am doing:

    User::all();

to get all the users from users table. I want to select all the users except current logged in user. How should I

4条回答
  •  名媛妹妹
    2021-01-31 16:36

    Using except() will accomplish the same thing a little more fluently:

    $users = User::all()->except(Auth::id());
    

    ...or, since you already have the User id:

    $users = User::all()->except($currentUser->id);
    

提交回复
热议问题