laravel eloquent Random Row query example
In this article, We will explain to you how to get random row data into the database using the Random Row Query.
The laravel eloquent provides many types of eloquent methods. so we can easily get random row data into the database using the inRandomOrder eloquent method.
There are two ways to get random data into the database. so you can see below the following example.
1 2 3 4 5 6 7 8 9 10 | //first way $students = DB::table('students') ->inRandomOrder() ->get(); //second way $students = DB::table('students') ->orderByRaw("RAND()") ->get(); |
Please follow and like us: