I want to get from database 10 random rows and then display it on paginate.
One page should display only 1
cat_id = 1
cat_id = 3
all() method returns a Collection while
paginate extends a Query Builder. So if you did not need any random results, you could call paginate directly like this
Now, the problem with random is that it works on a Collection so you cannot use it directly before calling paginate, so here I'm going to use
For e.g. to order the rows randomly and get only the first row with the cat_id the same as the current page number, you can do something like this,
I'm assuming that there are no gaps in cat_id here.