Hello Devs,

In this tutorial, we are going to learn how to add pagination In Laravel 7.

Follow this step by step guide given below:

Step 1:

 Add Route routes/web.php

Route::get('users', 'UserController@index');

Step 2: 

Create Controller app/Http/Controllers/UserController.php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class UserController extends Controller
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function index()
        $data = User::paginate(10);
        return view('users',compact('data'));

Step 3: 

Create Blade File resources/views/users.blade.php

<table class="table table-bordered">
            <th width="300px;">Action</th>
        @if(!empty($data) && $data->count())
            @foreach($data as $key => $value)
                    <td>{{ $value->name }}</td>
                        <button class="btn btn-danger">Delete</button>
                <td colspan="10">There are no data.</td>
{!! $data->links() !!}

Pagination with appends parameter

{!! $data->appends(['sort' => 'votes'])->links() !!}

Pagination with appends request all parameters

{!! $data->appends(Request::all())->links() !!}