Using Pagination in Laravel

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')

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

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

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