Mysql procedure with pagination in laravel 5?By Hardik Savani | January 11, 2016 | | 3671 Viewer | Category : Laravel MySql
Share this post:
You are working on laravel with mysql database. you had created mysql procedure for get data and you want to call procedure with pagination in laravel 5 then you can not directly make pagination as laravel document.If you are using directly MySQL stored Procedure in your controller, model or repository and you want to give pagination like this way :
$data = DB::select(DB::raw('CALL hardik("hari")'))->paginate(5);
This way you found error in your Laravel 5 website. we can't give directly this way pagination because your procedure will get all the data from database. but we can give pagination this way :
$page = Input::get('page', 1);
$paginate = 2;
$data = DB::select(DB::raw('CALL hardik("hari")'));
$offSet = ($page * $paginate) - $paginate;
$itemsForCurrentPage = array_slice($data, $offSet, $paginate, true);
$data = new \Illuminate\Pagination\LengthAwarePaginator($itemsForCurrentPage, count($data), $paginate, $page);
- Crop, Resize, Frames etc on selected image in php using Aviary
- PHP - Getting Started PHPUnit test with simple example
- Laravel 5.2 chat message module using socket.io, redis, express and nodejs from from scratch.
- How to create Event for Mail sending in Laravel 5.2?
- Bootstrap multiselect dropdown in popup using popupMultiSelect plugin
- How to get current route name in Laravel 5?
- Laravel 5 - whereIn and whereNotIn with subquery example using query builder
- AngularJS - How to render HTML value in ng-repeat ?