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 →</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 ??
Creating A Paginator Manually Sometimes you may wish to create a pagination instance manually, passing it an array of items. You may do so by creating either an Illuminate\Pagination\Paginator or Illuminate\Pagination\LengthAwarePaginator instance, depending on your needs.
There are several ways to paginate items. The simplest is by using the paginate method on the query builder or an Eloquent query. The paginate method provided by Laravel automatically takes care of setting the proper limit and offset based on the current page being viewed by the user.
Pagination works by selecting a specific chunk of results from the database to display to the user. The total number of results is calculated and then split between pages depending on how many results you want to return on a page.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With