How to get a random row with Laravel Eloquent or Fluent and PHP?

Spread the love

Sometimes, we want to get a random row with Laravel Eloquent or Fluent and PHP.

In this article, we’ll look at how to get a random row with Laravel Eloquent or Fluent and PHP.

How to get a random row with Laravel Eloquent or Fluent and PHP?

To get a random row with Laravel Eloquent or Fluent and PHP, we call inRandomOrder and get.

For instance, we write

$u = User::inRandomOrder()->get();

to use User::inRandomOrder()->get() to return a random entry in the users table.

Conclusion

To get a random row with Laravel Eloquent or Fluent and PHP, we call inRandomOrder and get.

Leave a Reply

Your email address will not be published. Required fields are marked *