Create Previous Next Simple Pagination in Laravel?

Create Previous Next Simple Pagination in Laravel?

In this post we will give you information about Create Previous Next Simple Pagination in Laravel?. Hear we will give you detail about Create Previous Next Simple Pagination in Laravel?And how to use it also give you demo for it if it is necessary.

Laravel provided two type pagination.


  • 1 | General Pagination
  • 2 | Previous-Next Simple Pagination


We all familiar with general pagination in laravel and also know how to make it. but laravel also provide provious-next simple pagination and some still not familiar with this laravel pagination functionality.


So, in this article I will share with you how to create simple pagination in laravel application steps by steps.


Preview



Step – 1 : Create New Laravel7 Application.


First, we need to create one fresh laravel application help of running the following artisan command in the terminal.



composer create-project laravel/laravel firstApp --prefer-dist


Step – 2 : Create Route


Now, we need to create one route for getting the data from the user’s table and then listing the data with pagination. first, you should add some dummy data in the users table.



Route::get('get-users', 'UserController@getUser')->name('get-users');


Step – 3 : Create Controller


Now, we need to create UserController.php files help of the following artisan command.



php artisan make:controller UserController


Now write the following in app/Http/Controllers/UserController.php file.



<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppUser;

class UserController extends Controller
{
    /**
     * Show the users listing
     *
     * @return IlluminateContractsSupportRenderable
     */
    public function getUser()
    {
    	$data = User::simplePaginate(10);
        return view('users', compact('data'));
    }
}


Step – 4 : Create Blade File


Into the last, we need to create blade file in resources/views/users.blade.php file and simply write the following layout into it.



<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Users Data</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

    <!-- Styles -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div >
        <table >
            <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Email</th>
            </tr>
            </thead>
            <tbody>
                @foreach($data as $key => $value)
                <tr>
                    <td>{{ $value->id }}</td>
                    <td>{{ $value->name }}</td>
                    <td>{{ $value->email }}</td>
                </tr>
                @endforeach
            </tbody>
        </table>
        {{ $data->links() }}
    </div>
</body>
</html>


i hope this article help a lot.

Hope this and post will helped you for implement Create Previous Next Simple Pagination in Laravel?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  46  =  49

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US