In this tutorial, we will see laravel eloquent inrandomorder() query example. The inRandomOrder method may be used to sort the query results randomly. 

Given below are two examples for laravel inRandomOrder query. 



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();
}


I hope this example helps you.