Laravel

Using Pagination in Laravel
18.01.2022
img

Pagination is a way of showing extensive data in a smaller part. Pagination in Laravel is very easy to use. It is integrated with the query builder and Eloquent ORM. Laravel pagination covers limit and offset automatically.                   

// app > http > controllers > PostController.php

class PostController extends Controller {

    public function getPost(){
      $posts = Post::all()
             ->orderBy('created_at', 'DESC')
             ->paginate(8);

      return view('index', compact('posts'));
    }
}

//  index.blade.php 
...        
<div>
   {{ $posts->links() }}
</div>

Append Parameter to Pagination

We can simply add the additional parameter to the pagination url by just using the following code.

{{ $posts->appends(request()->query())->links() }}

back to all posts