Laravel get all records with pagination

You can get all records of a particular table with pagination using paginate() method and display in laravel blade file.

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

    //Paginate method to display 10 records per page
    $users = DB::table('users')->paginate(10);
    //Pass data to view
    return view('home')->with('users', $users);
    //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

Related queries helps you to understand and may also used for implementation of current code snippet