Hi Developers,
To display the data in the paginate format in this example we use the simplePaginate() function in laravel, In this pagination it will display as the page numbers as the link buttons , In Custom Pagination we are using the custom pagination unlike default pagination it won't look like page numbers it will display only two buttons Next and Previous
Today we see both the Default and Custom Pagination.
Lets edit the code to display the data in the paginate format in this example we use the simplePaginate() function in laravel
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Tutorial;
class TutorialController extends Controller
{
public function index()
{
$tutorials= Tutorial::simplePaginate(10);
return view('tutorial.index', compact('tutorials'));
}
}
Example 1 : In this first example we are using the default Laravel pagination. In this pagination it will display as the page numbers as the link buttons , Lets see how its done
<html>
<head>
<title>How To Set Next Previous Link Button In Laravel Pagination ITSolutionsGuides</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"/>
</head>
<body>
<div class="container">
<h1>How To Set Next Previous Link Button In Laravel Pagination ITSolutionsGuides</h1>
<table class="table table-bordered">
<tr>
<th>ID</th>
<th>Title</th>
</tr>
@if(!empty($tutorials))
@foreach($tutorials as $tutorial)
<tr>
<td>{{ $tutorial->id }}</td>
<td>{{ $tutorial->title }}</td>
</tr>
@endforeach
@endif
</table>
@if(!empty($tutorials ))
<div class="paginationWrapper">
{{ $tutorials ->links() }}
</div>
@endif
</div>
</body>
</html>
Example 2 : In this example we are using the custom pagination unlike default pagination it won't look like page numbers it will display only two buttons Next and Previous
@if(isset($tutorials ))
@if($tutorials ->currentPage() > 1)
<a href="{{ $tutorials ->previousPageUrl() }}">Previous</a>
@endif
@if($tutorials ->hasMorePages())
<a href="{{ $posts->nextPageUrl() }}">Next</a>
@endif
@endif
We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.
Be the first to know about releases and tutorial news and solutions.
We care about your data in our privacy policy.
ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.
Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides