Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

monstajamss's avatar

Laravel Custom Pagination (Html & CSS)

I have my html pagination like this with my css

<div class="pagination">
	<a href="#" class="next">
			Next
		<i class="fa fa-angle-right"></i>
	</a>
</div>

How can i make laravel paginate using above struction with Next and Previous

0 likes
12 replies
monstajamss's avatar

when i use simplepaginate it shows previous on the homepage which is not meant to show

Blade

<div class="pagination">
			<a href="#" class="next">
				Next  {{ $posts->links() }}
				<i class="fa fa-angle-right"></i>
			</a>
		</div>

Controller.php

 $posts= Post::latest()->simplepaginate(15);
monstajamss's avatar

@sti3bas i am trying to use simplepaginate and it is giving previous on the homepage

how do i solve this

jlrdw's avatar

I showed you already.

Use regular paginate with a custom template

https://laracasts.com/discuss/channels/guides/paginator-another-episode

Write a custom template any way you desire it to be. I even gave an example, I do not know what else to do.

Of course review the documentation on it as well.

You aren't acutally writing "previous" there also are you?

Laravel simplepaginate takes care of that. Of course previous will show if you have written it in, it will always show up.

This:

{{ $posts->links() }}

Not

previous  {{ $posts->links() }}
monstajamss's avatar

@jlrdw yeah i have done that but why is previous showing on the homepage i thought Next is the only thing that is meant to show on the home page right?

jlrdw's avatar

Did you clear browser and view cache between your changes?

jlrdw's avatar

I usually don't use simple paginate, but if there are no previous, it's greyed out and disabled, that's normal behavior.

Again, you can change how the template shows this stuff. Did you see my example in the link I gave.

But what's wrong with previous being disabled? It's only enabled if user in on page 2 or higher.

monstajamss's avatar

@jlrdw i said it worked fine but how can i change url structure and also how can i make somethings show on the homepage alone and not the second page.

jlrdw's avatar
jlrdw
Best Answer
Level 75

Having different templates: for example on one of my pages I have

{{ $dogs->links('cpag.custom') }}

cpag.custom is a custom template.

Under views\cpag is where I store my custom templates. Remember, every possible way of showing pagination isn't provided out of the box. So practice a custom pagination template.

jlrdw's avatar

@monstajamss remember also in a custom template you can control if previous is shown or not shown.

Just use a blade if as needed.

Please or to participate in this conversation.