Query random with Laravel and exclude a specific row

How can I create a query random with laravel and exclude a specific row

I tried this :

return $this->user
            ->get()
            ->random(1)
            ->where('id', '!=', 1);

Upvotes: 1

Views: 259

Answers (1)

Daan
Daan

Reputation: 12246

You're where needs to be first.

return $this->movie::where('id', '!=', 1)
            ->get()
            ->random(1);

Upvotes: 3

Related Questions