Foreach paginate pages Laravel Hello. I have a code:
$posts = Post::paginate(100);
How I can foreach pages of pagination and show results? I need in every file write a posts.
foreach($posts as $page => $post) {
//put on file current posts of page with file name: file-posts-$page.txt
}
How I can do it?
pagination does not sound right here.
If you can reasonably load all posts into memory at once, use chunk() on the collection. If not, then do it with take() and offset() to step through all the posts
please example
Doesn't make sense, as there are examples in the documentation.
https://laravel.com/docs/5.8/queries
Right on that page is the menu:
quote
Introduction
Retrieving Results
Chunking Results
Aggregates
Selects
Raw Expressions
Joins
Unions
Where Clauses
Parameter Grouping
Where Exists Clauses
JSON Where Clauses
Ordering, Grouping, Limit, & Offset
Conditional Clauses
Inserts
Updates
Updating JSON Columns
Increment & Decrement
Deletes
Pessimistic Locking
unquote
So why would someone need to give example, when Taylor has already.
Do you need the post formatting in this text file?
To show pagination, put this in your view, where you want display pagination links
{{ $posts->links() }}
I guess it will be better if try explain what are you trying to achieve, so we can help better.
Please sign in or create an account to participate in this conversation.