Laravel Eloquent inRandomOrder() Query Example

10-Apr-2023

.

Admin

Laravel Eloquent inRandomOrder() Query Example

Hi Guys,

Today, i would like to show you laravel eloquent inrandomorder() query example. You will learn inrandomorder() query in laravel application with example.

The inRandomOrder method may be used to sort the query results randomly. For example, you may use this method to fetch a random user.

This tutorial will give you simple example of inrandomorder in laravel query builder.This tutorial will give you simple example of inrandomorder query in laravel.

Here I will give two example for laravel inRandomOrder query. So let's see the bellow example.

Example 1 : Query


/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$randomUser = DB::table('users')

->inRandomOrder()

->get();

}

Example 2 : Query

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

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

}

It will help you...

#Laravel 7

#Laravel

#Laravel 6