Today now in this blog I will show you how to mysql procedure with pagination in laravel. When we are working on laravel with mysql database. we need to created mysql procedure for get data and we want to call procedure also with pagination in laravel then we cannot directly make pagination as laravel document. But if we are using directly MySQL stored Procedure in our controller, model or repository and we want to give pagination as like this way :
$data = DB::select(DB::raw('CALL srs("hari")'))->paginate(5);
So on this way we found an error in our Laravel website. We can’t give it directly this way pagination because our procedure will get all the data from the database. but we can give pagination this way :
$page = Input::get('page', 1); $paginate = 2; $data = DB::select(DB::raw('CALL srs("hari")')); $offSet = ($page * $paginate) - $paginate; $itemsForCurrentPage = array_slice($data, $offSet, $paginate, true); $data = new \Illuminate\Pagination\LengthAwarePaginator($itemsForCurrentPage, count($data), $paginate, $page); return view('test',compact('data'));
Thanks for read this, I hope it will you. You can also follow us on Facebook.