Getting Random rows in Laravel Eloquent.

2019-12-10 16:26:05 Irshad Laravel

How to select random rows in Laravel?

Sometime we have to get records from database in random order, here I am going to show some ways to get / select random records from database in Laravel.

In laravel 5.2 or above you can use comething like below to get random rows in Laravel.

YourModal::inRandomOrder()->get();

or

YourModal::orderBy(\DB::raw('RAND()'))->get();

This post is submitted by one of our members. You may submit a new post here.

Related Tricks