pagination not styled in laravel 5.5

Viewed 31388

Here is my code where I am showing the paginations of my blog posts !!

<div class="clearfix">
    {{ $posts->render() }}
    <a class="btn btn-secondary float-right" href="#">Older Posts &rarr;</a>
</div>

Here is the controller where the pagination function is called.

public function index()
{
    $posts = post::where('status',1)->paginate(2);
    return view('user.blog',compact('posts'));
}

I have tried lot, but my pagination displayed but not properly styled !! Why ??

Here I show what is happening above the black line !!

4 Answers

To display the pagination links in your blade view:

{{ $posts->links() }}

Or if you need to specify Bootstrap 4:

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

Laravel docs: https://laravel.com/docs/5.5/pagination

For pretty boostrap 4 pagination, simply call this:

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

For Laravel 8

Laravel includes pagination views built using Bootstrap CSS. To use these views instead of the default Tailwind views, you may call the paginator's useBootstrap method within the boot method of your App\Providers\AppServiceProvider class:

use Illuminate\Pagination\Paginator;

public function boot()
{
    Paginator::useBootstrap();
}

Laravel docs: https://laravel.com/docs/8.x/pagination

Related