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

后端 未结 4 1942
无人共我
无人共我 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:35

    You can get the current user's id with auth()->id(). Then pass that to the query:

    $users = User::where('id', '!=', auth()->id())->get();
    

提交回复
热议问题