Reputation: 1081
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.
Upvotes: 4
Views: 1784
Reputation: 1
If you have any where condition ? You can use this easily
$perPage = 25;
$users = User::where('age', '20');
return $users->paginate($perPage);
Upvotes: 0
Reputation: 163748
Try this code:
$users = User::paginate(25);
The thing is paginate()
is kind of doing get()
for you. And all()
does it too.
Upvotes: 7