Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Paginate listed users

I have a Laravel aplication, with standard Authentication implemented. I would like to get the paginated list of the users in a table, but I get this error:

BadMethodCallException in Macroable.php line 81: Method paginate does not exist.

Here is the code:

$users = User::all()->paginate(25);

If I use this without calling the paginate() method, everything works well. Am I doing something wrong? I searched a lot, but I cannot find the answer.

like image 400
Zoli Avatar asked Oct 26 '25 09:10

Zoli


1 Answers

Try this code:

$users = User::paginate(25);

The thing is paginate() is kind of doing get() for you. And all() does it too.

like image 126
Alexey Mezenin Avatar answered Oct 28 '25 23:10

Alexey Mezenin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!