Friday, March 6, 2020

Next And Previous Button Pagination in Laravel 6 ?

Next And Previous Button Pagination in Laravel 6 ?


Do you want to add the following Next And Previous Button Pagination in Laravel 6 ? If so, I will help you create a simple Next And Previous Button Pagination in Laravel 6. We will only adjust Next And Previous Button Pagination in Laravel 6.

We can add the following and previous link in the pagination with simplePaginate () in the Laravel 6 and Laravel 5 application. Laravel offers the new elaborate SimplePaginate () method to add simple Next And Previous Button Pagination in Laravel 6.

If you also want to add a pagination using the following and previous link, do the following steps.


Step(1): Create Route:


In the first step, we create simple routes to reach and display users. So add a new route to the web.php file:

routes/web.php


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


Step(2): Create Controller:


Now we create a new UserController using the index () method. We write a simple paging code in index (). So below as follows:

app/Http/Controllers/UserController.php
<?php

   

namespace App\Http\Controllers;

   

use Illuminate\Http\Request;

use App\User;

   

class UserController extends Controller

{

    /**

     * The attributes that are mass assignable.

     *

     * @var array

     */

    public function index()

    {

        $users = User::simplePaginate(5);

        return view('users', compact('users'));

    }

}


Step(3): Create View File:


In this last step, we create a simple blade file and show users the pagination. So let's add the following code:

resources/views/users.blade.php
<!DOCTYPE html>

<html>

<head>

    <title>Laravel 6 Pagination with Next And Previous Button - MyitBuddies.com</title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">

</head>

<body> 

   

<div class="container">

    <h1>Laravel 6 Pagination with Next And Previous Button - MyitBuddies.com</h1>
   

    <table class="table table-bordered">

        <tr>

            <th>ID</th>

            <th>Name</th>

        </tr>

        @foreach($users as $user)

        <tr>

            <td>{{ $user->id }}</td>

            <td>{{ $user->name }}</td>

        </tr>

        @endforeach

    </table>

   

    {{ $users->links() }}

</div>

   

</body>

</html>


Ok, now you need to create some dummy records in the user table.

Then you can check it out.

I hope this tutorial Next And Previous Button Pagination in Laravel 6 could help you ...

0 comments:

Post a Comment

Please don't enter any spam link in the comment box.