Add a seed
$book = Book::inRandomOrder('foobar')->paginate(10);
https://laravel.com/api/8.x/Illuminate/Database/Query/Builder.html#method_inRandomOrder
I have a collection of 50 items (model = Books) and I would like to return them uniquely 10 per page (paginated) but in a random order. I tried using Book::inRandomOrder()->paginate(10), but when I go to page 2, 3, etc... I see books that were already shown on page 1 or some previous page.
I did a workaround with adding a randomValue column to the table and then doing orderBy(“randomValue”)->paginate(10), but that seems like a hack way to do it.
What’s the better way to do this?
Add a seed
$book = Book::inRandomOrder('foobar')->paginate(10);
https://laravel.com/api/8.x/Illuminate/Database/Query/Builder.html#method_inRandomOrder
Please or to participate in this conversation.