Mysql procedure with pagination in laravel 5?By Hardik Savani | January 11, 2016 | | 2247 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);
- Laravel 5.3 - How to create SEO friendly sluggable URL
- Laravel 5 - Example of Database Seeder with insert sample data
- Laravel 5 - Multiple markers in google map using gmaps.js
- How to resolve - tokenmismatchexception in verifycsrftoken.php Laravel 5 Ajax ?
- HTML/FORM not found in Laravel 5?
- How to set bootstrap timepicker using datetimepicker library example code
- Laravel notification message popup using toastr js plugin
- How to create and use Middleware in Laravel 5?