In this tutorial, we will learn Laravel Pagination Get Current Page Example
Create Route:
routes/web.php
Route::get('users', 'UserController@index');
Create Controller:
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::paginate(10)->currentPage();
return view('users', compact('users'));
}
}
Create View File:
resources/views/users.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Laravel Pagination Get Last Page Example - NiceSnippest.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 Pagination Get First Page Example - NiceSnippest.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>
May this example help you.