How to sort the results of models randomly in Laravel
Categorized as Laravel
To someone who didn’t know, there is a pretty and short Eloquent method to use on your model results to get things in random order. See the code below:
use App\Models\Post;
return Post::inRandomOrder()->get();
From the official documentation:
$randomUser = DB::table('users')
->inRandomOrder()
->first();