php - Laravel 5 Pagination linking to wrong place -


i'm updating 1 of projects laravel 5 4.2. i'm aware lot has changed paginator class can't figure out why isn't working. call paginate() on eloquent models @ multiple locations in project , every thing works great.

but same project has profile searching page filters have call huge custom db::table() query. after want build paginator object results.

$q = \db:: huge query here....  // execute query $results = $q->get();  // pagination information , slice results. $perpage = 20; $total = count($results); $start = (paginator::resolvecurrentpage() - 1) * $perpage; $sliced = array_slice($results, $start, $perpage);  // eager load relation. $collection = profile::hydrate($sliced); $collection->load(['sports', 'info', 'profileimage']);  // create paginator instance. $profiles = new paginator($collection->all(), $total, $perpage);  return $profiles; 

my problem is links generated after calling $profiles->render() link root of project instead of current page.

example: links located @ mysite.com/profiles link mysite.com/?page=2 instead of mysite.com/profiles?page=2

my code worked great in laravel 4.2, il link below reference:

laravel 4.2 code works:

$q = \db:: huge query here....  // execute query $results = $q->get();  // pagination information , slice results. $perpage = 20; $total = count($results); $start = (paginator::getcurrentpage() - 1) * $perpage; $sliced = array_slice($results, $start, $perpage);  // eager load relation. $collection = profile::hydrate($sliced); $collection->load(['sports', 'info', 'profileimage']);  // create paginator instance. $profiles = paginator::make($collection->all(), $total, $perpage);  return $profiles; 

any welcome. thanks!

i fixed after hours of work!

i found out can pass path paginator. can see can done passing array 5th argument when building paginator object. array overwrite options pass it. need overwrite path option. i'm getting current path using paginator::resolvecurrentpath().

so code looks like:

// create paginator instance. $profiles = new paginator($collection->all(), $total, $perpage, paginator::resolvecurrentpage(), [     'path' => paginator::resolvecurrentpath() ]); 

for people interested, paginator constructor looks like:

__construct($items, $total, $perpage, $currentpage = null, array $options = []) 

it weird need pass manually , consider bug.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -