iori
iori

Reputation: 3506

How to query all except one in Laravel 4?

CONTROLLER

public function index() {
    $users = User::all(); // Is there a way to chain it with the except method or sth like that
    return View::make('distributors.index')->with('users',$users);
}

GOAL

I want to query all of my users table, but one.

I want to list all the user(s) for my client, but I want to hide my self.

Question

How do I do that ? Am I approaching it in the right way ?

Feel free to give me any suggestions for improvement.

Upvotes: 2

Views: 10080

Answers (1)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100195

If you mean except currently logged in user, then do:

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

Upvotes: 10

Related Questions