Kylian
Kylian

Reputation: 131

Laravel limit with paginate

Do you know why I receive all the records with this query :

$pictures = Picture::latest()->limit(100)->paginate(18);

I should only get 100, but he gives them all to me It's probably a parameter I'm forgetting but it doesn't seem illogical to me

Thanks in advance

Upvotes: 1

Views: 5206

Answers (2)

Brennan James
Brennan James

Reputation: 452

$pictures = Picture::latest()->simplePaginate(18);

Try simplePaginate() instead.

Upvotes: 0

ImAtWar
ImAtWar

Reputation: 1143

The paginate query builder overrides your limit method.

https://laravel.com/docs/8.x/pagination#paginating-query-builder-results

Paginating Query Builder Results The paginate method automatically takes care of setting the query's "limit" and "offset" based on the current page being viewed by the user.

Upvotes: 4

Related Questions