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
.