Mysql storedprocedure with pagination in laravel 5
You are working on laravel with MySQL database. you had created MySQL stored 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 store("6pm")'))->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 :
$pageNumber = Input::get('pageNumber', 1);
$paginate = 2;
$data = DB::select(DB::raw('CALL store("6pm")'));
$offSet = ($pageNumber * $paginate) - $paginate;
$itemsForCurrentPage = array_slice($data, $offSet, $paginate, true);
$data = new \Illuminate\Pagination\LengthAwarePaginator($itemsForCurrentPage, count($data), $paginate, $page);
return view('test',compact('data'));
Comments
Post a Comment