How to implement pagination in Laravel
Step 1 :- Setting paginate in controller
Example :–
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use DB;
class AdminController extends Controller
{
public function dashboard()
{
$products=DB::table('your_table_name')->paginate(5);
return view('You'r_blade_file', compact('products'));
}
}
Step 2 :- Blade View page pagination work
Example :–
<table id="customers">
<thead>
<tr>
<th>name</th>
<th>food name</th>
<th>GI</th>
<th>food type</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody id="table-data">
@foreach($products as $data)
<tr>
<td scope="row">{{ $data->name}}</td>
<td>{{$data->food_name}}</td>
<td>{{$data->gi_number}}</td>
<td>{{$data->food_type}}</td>
</tr>
@endforeach
</tbody>
</table>
<div class="d-flex justify-content-center">
///////////Pagination////////////
{!! $studentData->links() !!}
</div>
Step 3 :- Result
Example :–