Pagination in Laravel

Sometimes your website fetching data from database like hundreds or thousands data list. It will make your page slow and may cause to reduce your site traffic.

Pagination is very complicated feature through php but laravel makes it very prosperous. Its generate intelligent "range" of links based on the current page. The generated HTML is compatible with the Bootstrap CSS framework.


In this route file we are trying to set pagination for users where 10 limit has been set for per page.

Route::get('user', function() {
   // $users have 10 records from users table
    $users = App\User::paginate(10);
    return view('users', compact('users'));


Creating pagination links using the render method

<h1>Our User List</h1>
@foreach($users as $user)
    <li>{!! link_to( "user/{$user->name}", $user->name ) !!}</li>

{!! $users->render() !!} 


Something to say? Tell us in comment section.