Of course i read the documentation 4 times before asking here , you didn't get my question, usual pagination is used when retrieving data from multiple rows in database , but what i want to paginate is the body which is only one instance but sometimes it is too long to display in one page
Split a page into multiple pages using pagination
I am making a blog , in the blog.show.blade view sometimes the body is too long and want to divide it into parts and add 'previous' , 'next' buttons , but the problem is that the body is stored all in one column in database so how can i paginate it ?
show.blade.php (the article show view) :
@if($post->image_url)
<div class="post-image">
<img class="mb-5" src="{{ $post->image_url }}" alt="{{ $post->slug }}">
</div>
@endif
<div class="post-title">
<h1 class="mb-4" >{{ $post->title }}</h1>
</div>
<div class="post-body mb-5">
{!! $post->body_html !!}
</div>
</div>
</div>
Easier if you are ok to put something indicating page break in your post
Then you know where to split it.
Otherwise, you have to read so many characters and then find the next parent element (eg a <div>). Take the first part and count how many characters where in the first part. If you don't split it on a parent element then the html will be broken on page 2
Output the first part to the view
Have a link to part 2, when you get the part 2 route, read the contents again and discard everything up to the previous character count. then repeat incase you need page 3...
Not simple at all.
Please or to participate in this conversation.