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

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);

If you are using the Auth helper, use this.

User::where('id', '!=', Auth::user()->id)->get();

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

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

Tags:

Mysql

Php

Laravel