Level 3
Check here:
https://laravel.com/api/5.4/Illuminate/Contracts/Pagination/LengthAwarePaginator.html
Use one of the functions that work with the URL of the pages.
Hi everyone,
I'm using raw sql to get data from the database, but now i can't use the method paginate, so i manually paginate my array:
$parts= DB::select("SELECT pro.name AS 'pro_name', parts.* FROM programs pro, parts
WHERE pro.id = parts.Pro_id)->paginate(4); -> not working
$parts= DB::select("SELECT pro.name AS 'pro_name', parts.* FROM programs pro, parts
WHERE pro.id = parts.Pro_id);
$col = new Collection($parts);
$perPage = 5;
$currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
$parts= new LengthAwarePaginator($currentPageSearchResults, count($col), $perPage);
but when in my view i use this:
{!! $parts->appends(Input::except('page'))->render() !!}
I get redirected to : http://localhost:8000/?page=2 instead of http://localhost:8000/Parts?page=2
Does anyone knows how to fix this?
Regards
Just use the api for 5.3 then:
https://laravel.com/api/5.3/Illuminate/Contracts/Pagination/LengthAwarePaginator.html
edit:
@RJA Try this
$parts->withPath('Parts'); // or 'Parts/'
Please or to participate in this conversation.