Pagination in laravel

Updated at 11-Jan-2021, By samar

Pagination in laravel

With this article, we will examine several different instances of how to solve the "Pagination in laravel".

  • Use paginate method in controller and call links() method in view file to display pagination links

    //app\Http\Controllers\<HomeController>.php
    //Paginate method to display 10 records per page
    $users = DB::table('users')->paginate(10);
    //Pass data to view
    return view('home')->with('users', $users);
    
    //resources\views\<home>.blade.php
    //view file code to display pagination
    {{ $users->links() }}
    

    You can use paginate method by passing the number of records you want to display per page and you can call the links() methon in view file to display the pagination links. 

Back to code snippet queries related laravel