Joydip's avatar

Looping through custom pagination result works only for first page not the other page?

This is my custom pagination in Laravel 5.4

    $currentPage = LengthAwarePaginator::resolveCurrentPage();
    if (is_null($currentPage)) {$currentPage = 1;}
    $collection1 = new Collection($job_ids);
    $perPage = 20;
    $currentPageSearchResults = $collection1->slice(($currentPage - 1)  * $perPage, $perPage)->all();
    $job_ids = new LengthAwarePaginator($currentPageSearchResults, count($collection1), $perPage);
    $job_ids->setPath($request->url());
    $job_ids->appends($request->except(['page']));
   return view('searchJobs/job_search_with_filters', compact('job_ids', 'collection'));

Now when looping through the array in view only the page one is parsing the 'job_ids' while clicking on other paginate link does not parse it.

Any help would be appeciated. Thanks

0 likes
1 reply
J_shelfwood's avatar

Try using dd() at every line to see where the weird behaviour starts.

Please or to participate in this conversation.