Laravel Pagination Get Previous Page Tutorial
Teams applying “Laravel Pagination Get Previous Page Tutorial” in a production project can use the complete guide to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.
Before copying the example into a live application, confirm version-specific behaviour with the official Laravel website and test it against the project’s actual database and runtime.
Hi guys,
Today i will explained to the the laravel pagination get previous page in your laravel project.the laravel pagination is so easy to use.so you can just follow my step by step and learn laravel pagination get previous page.
So let's start to the example and follow to the my all step.
Solution
{{ $users->previousPageUrl() }}
Step 1: Create a User Controller
Next you can require to the User Controller so create a User Controller in just following command through.
app/Http/Controllers/UserController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
class UserController extends Controller
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$users = User::paginate(10);
return view('users', compact('users'));
}
}
Step 2: Add Blade File
Last step to create a users.blade.php file and use this code.
resources/views/users.blade.php
<!DOCTYPE html>
<html>
<head>
<title>laravel pagination get previous page</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1>laravel pagination get previous page</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>
<ul class="pagination">
<li class="page-item"><a class="page-link" href="{{ $users->nextPageUrl() }}">Next</a></li>
<li class="page-item"><a class="page-link" href="{{ $users->previousPageUrl() }}">Previous</a></li>
</ul>
</div>
</body>
</html>
Ok, now you have to create some dummy records on users table.
So, finally we are done with our code we can get below output.
php artisan serve
Browser url run : http://localhost:8000/users
Output:
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial