Laravel get all records with pagination

Updated at 24-Sep-2021, By samar

Laravel get all records with pagination

In this session, we are going to try to solve the "Laravel get all records with pagination" puzzle by using the computer language.

You can get all records of a particular table with pagination using paginate() method and display in laravel blade file.
  • 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