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);
8
votes
If you are using the Auth helper, use this.
User::where('id', '!=', Auth::user()->id)->get();
0
votes
Use Auth;
Use App\User;
public function index()
$id = Auth::id();
$result = User::where('id', '!=', $id)->get();
dd($result);
0
votes
App\Models\User::whereKeyNot(auth()->id)->get()
Using 'except' actually retrieves ALL users, then performs an extra operation on the collection to remove the current user, which is not as effective.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more