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

roddyp's avatar

Laravel 5.5 Pagination for Bootstrap 4

How do I get the render method to output HTML for Bootstrap 4 rather than 3? I see bootstrap-4.blade.php and other view files in \Paginations\resources\views, but I don't know how/where to specify which one to use.

Sorry for the noob question as I'm still feeling my way around this stuff, and most of the info I've found seems to refer to earlier Laravel releases.

0 likes
15 replies
36864's avatar

If you don't want to specify the file every time you call links, just rename bootstrap-4.blade.php to default.blade.php. Remember to make a backup of the default in case you want to switch back.

1 like
roddyp's avatar

Thanks.

@36864 Won't that get overwritten if/when I upgrade the Laravel version of the project?

@gcwilliams In 5.5 links() is replaced with render() which appears to work similarly. Also not clear how to use the 5.5 paginator views in-situ rather than copying them to resources\views?

After looking into the code. I tried this which works, but I'm not yet familiar with the pagination::syntax?

{{$users->render("pagination::bootstrap-4")}}

1 like
roddyp's avatar
roddyp
OP
Best Answer
Level 2

After a bit more digging, this approach works and should be robust. I've just stuck it in bootstrap\app.php for now

Illuminate\Pagination\AbstractPaginator::defaultView("pagination::bootstrap-4");
Illuminate\Pagination\AbstractPaginator::defaultSimpleView("pagination::simple-bootstrap-4");

This sets the default view for both simple and normal paginators.

11 likes
jlrdw's avatar

In 5.5 links() is replaced with render()

Again

And you realize the pager css is just

ul.pagination li {
    display: inline;
    font-size: 12px;
    font-weight: bold;
}

ul.pagination li a {

    color: black;
    padding: 8px 8px;
    text-decoration: none;
    transition: background-color .3s;
    border: 1px solid #ddd;
    margin: 4px;
}

ul.pagination li a.active {
    background-color: #4CAF50;
    padding: 8px 8px;
    margin: 4px;
    color: white;
    border: 1px solid #4CAF50;
}

ul.pagination li.active {
    /*background-color: #4CAF50;*/
    background-color: #687282;
    padding: 8px 8px;
    margin: 4px;
    color: white;
    border: 1px solid #4CAF50;
}

/*ul.pagination li a:hover:not(.active) {background-color: #ddd;}*/
ul.pagination li a:hover {background-color: #999999;}

ul.pagination li.disabled {
    /*background-color: #cccccc;*/
    color: #ddd;
    padding: 8px 8px;
    border: 1px solid #ddd;
    margin: 4px;
}

You can do your own any time and just load the little css file, but one also needed for media query if mobile friendly also.

gcwilliams's avatar

pagination::is just a namespace. If you vendor publish the views like on the page I linked above, it will put them into:

resources/views/vendor/pagination

It puts them in a vendor/pagination. That is basically the namespace. So all the :: stuff is doing is looking in that namespace.

1 like
roddyp's avatar

@jlrdw "Again" ??? Have I missed something?

Pagination CSS - yes, understand all that - what I don't yet understand is how requesting a view called *pagination::*foobar maps to vendor/laravel/framework/src/Illuminati/pagination/resources/views/foobar.blade.php

roddyp's avatar

Ah - just drilling down from @gcwilliams answer re namespace. Again, it all seems quite different with 5.5...

roddyp's avatar

OK, understand it now. PaginationServiceProvider specifies the view 'namespace' pagination with the loadViewsFrom call.

$this->loadViewsFrom(__DIR__.'/resources/views', 'pagination');
gcwilliams's avatar

You should really use the vendor publish command. While it may find it in the framework folder, you really don't want an upgrade of the framework to change things and change your code. If it is published, it becomes in your own files and unless you overwrite it, it won't change.

Also, as far as I can tell. the links() method still works in 5.5. It just is an alias now for render

gcwilliams's avatar

@jlrdw no I have not figured it out. It is a bug in the site. I have reported it, but since it is probably only happening to a few people it probably isn't high on Jeffrey's list.

If you look it really is just displaying it twice. It is not double posting or anything like that. Editing one, edits them both. Same with deleting. Odd bug, but can't help it unfortunately.

roddyp's avatar

@gcwilliams : links() vs. render() . Thanks, you're right.

Vendor publish : I want to use the BS4 views that ship with Laravel 5.5. I've no plans to mod them, and would actually prefer them to be updated with the rest of the framework if necessary.

TimM1968's avatar

This worked for me:

{{ $employees->links( "pagination::bootstrap-4") }}

After doing:

php artisan vendor:publish 

...and selecting

[ ] Tag: lavarel-pagination

from the menu.

3 likes
copain's avatar

@roddyp youre answer works thank you... i was using bootstrap 3 in laravel but when i shifted to bootstrap 4 pagination come out ugly then i came across with your'e answer then it works hehe Thank you..

Please or to participate in this conversation.