How we can paginate through random records in laravel? for example:
$products = Product::all()->orderBy(DB::raw(\'RAND()\'));
$products->paginate(4);
$
Whe you dive into the documentation of mysql and search for the RAND() functionality you will see you can use a "seed".
By using a seed you will always get the same results that are randomised.
Example:
$products = Product
::all()
->orderBy(DB::raw('RAND(1234)'))
->paginate(4);
You can generate your own seed and store in in a session or something to remember it.
Update
The Laravel query builder now has a function that does exactly the same:
$products = Product
::all()
->inRandomOrder('1234')
->paginate(4);