RJA's avatar
Level 1

Manual Pagination not working

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

0 likes
4 replies
RJA's avatar
Level 1

i forgot to mention i'm using laravel 5.3, will this work?

Please or to participate in this conversation.