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
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();
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);
Use Auth;
Use App\User;
public function index()
$id = Auth::id();
$result = User::where('id', '!=', $id)->get();
dd($result);