'How to have laravel pagination links using the bootstrap 4 default pagination styles?
I'm using laravel default pagination with:
{{$posts->links()}}
and the pagination works, the links appear and it works correct.
But the style is like this:
Do you know why is not using the bootstrap 4 default styles? I'm using Bootstrap 4.
Also I have inside views/vendor/pagination the files:
- bootstrap4-blade.php
-default.blade.php
-semantic-ui.blade.php
-simple-bootstra-4.blade.php
-simple-default.blade.php
Generated HTML:
<ul class="pagination">
<li class="disabled"><span>«</span></li>
<li class="active"><span>1</span></li>
<li><a href="http://proj.test/user/profile?page=2">2</a></li>
<li><a href="http://proj.test/user/profile?page=2" rel="next">»</a></li>
</ul>
In "http://proj.test/css/app.css" it appears:
.pagination {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
padding-left: 0;
list-style: none;
border-radius: 0.25rem;
}
.page-item:first-child .page-link {
margin-left: 0;
border-top-left-radius: 0.25rem;
border-bottom-left-radius: 0.25rem;
}
.page-item:last-child .page-link {
border-top-right-radius: 0.25rem;
border-bottom-right-radius: 0.25rem;
}
.page-item.active .page-link {
z-index: 2;
color: #fff;
background-color: #0FACF3;
border-color: #0FACF3;
}
.page-item.disabled .page-link {
color: #868e96;
pointer-events: none;
background-color: #fff;
border-color: #ddd;
}
.page-link {
position: relative;
display: block;
padding: 0.5rem 0.75rem;
margin-left: -1px;
line-height: 1.25;
color: #0FACF3;
background-color: #fff;
border: 1px solid #ddd;
}
.page-link:focus,
.page-link:hover {
color: #097aad;
text-decoration: none;
background-color: #e9ecef;
border-color: #ddd;
}
.pagination-lg .page-link {
padding: 0.75rem 1.5rem;
font-size: 1.25rem;
line-height: 1.5;
}
.pagination-lg .page-item:first-child .page-link {
border-top-left-radius: 0.3rem;
border-bottom-left-radius: 0.3rem;
}
.pagination-lg .page-item:last-child .page-link {
border-top-right-radius: 0.3rem;
border-bottom-right-radius: 0.3rem;
}
.pagination-sm .page-link {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
line-height: 1.5;
}
.pagination-sm .page-item:first-child .page-link {
border-top-left-radius: 0.2rem;
border-bottom-left-radius: 0.2rem;
}
.pagination-sm .page-item:last-child .page-link {
border-top-right-radius: 0.2rem;
border-bottom-right-radius: 0.2rem;
}
In the page is loaded:
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,400,600,700" rel="stylesheet">
<link href="http://proj.test/css/app.css" rel="stylesheet" type="text/css">
<link href="http://proj.test/css/toastr.min.css" rel="stylesheet" type="text/css">
<link href="http://proj.test/css/bootstrap-datetimepicker.css" rel="stylesheet" />
Solution 1:[1]
You can customize the view used to display pagination passing it as a parameter of the links
method:
{{ $paginator->links('your.view') }}
You can even customize the default view applied using Paginator::defaultView
in your AppServiceProvider
:
use Illuminate\Pagination\Paginator;
public function boot()
{
Paginator::defaultView('pagination::view');
}
Check out the docs for further information.
Solution 2:[2]
Because the view is not yet available, we need to publish the view. Please run the following command in the terminal / CMD:
php artisan vendor:publish --tag=laravel-pagination
Solution 3:[3]
If laravel pagination is not using bootstrap paginations style, then try the following code in AppServiceProvider.php file to make bootstrap pagination.
use Illuminate\Pagination\Paginator;
public function boot()
{
Paginator::useBootstrap();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Asur |
Solution 2 | Riki krismawan |
Solution 3 | dev |