Here we ‘ll see, how easy is pagination in laravel, in previous post we saw about routing in laravel, here pagination is much more simpler that routing.
In the last post we just showed all the data from database, here we ‘ll paginate that data by limiting 5 results per page.
We ‘ll take some code from the last post and edit it here, please check previous post for reference,
Routing
Route for our controller will be same as in previous post,
Controller logic will be slightly modified, we call paginate function here,
1
2
3
4
5
publicfunctiongetFromDb(){
$users=User::paginate(5);
returnview('sample')->withDetails($users);
}
View for rendering pagination
In view file, sample.blade.php we render the pagination function which we used in the controller ,
1
{!!$details->render()!!}
the above line of code, renders the pagination, we can place that line in sample.blade.php where ever we want our pagination,
complete sample.blade.php file will be as follows,
Pagination in LaravelPagination in Laravel
This is how laravel makes pagination a breeze. Feel free to check previous posts on routing in laravel , database setup in laravel
Pagination in Laravel
Reviewed by Unknown
on
06:08:00
Rating: 5
Search This Blog
About Me
Hello, my name is Johnright.
I am internet marketer and i am PHP and PYTHON web developer.