Are you looking for example of laravel 8 pagination example blade. if you have question about laravel 8 pagination with user table then i will give simple example with solution. i explained simply step by step laravel 8 pagination tutorial. let’s discuss about pagination in laravel 8.
We know pagination is a primary requirement of each and every project. so if you are beginner with laravel than you must know how to use pagination in laravel 8 and what is other function that can use with laravel 8 pagination.
In this example i will explain you from scratch how to working with laravel pagination. so let’s follow bellow tutorial for creating simple example of pagination with laravel 8.
Step 1: Add Route
First thing is we put one route in one for list users with pagination. So simple add both routes in your route file.
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('users', [UserController::class, 'index']);
Step 2: Create Controller
Same things as above for route, here we will add one new method for route. index() will return users with pagination data, so let’s add bellow:
app/Http/Controllers/UserController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$data = User::paginate(5);
return view('users',compact('data'));
}
}
#laravel #php #web-development #programming #developer