Monday, March 13, 2017

How to remove query string page from the first page of laravel pagination?

I'm using pagination like the following:

public function index()
    {
        $jobs = Job::paginate(5);
        return view('job.index', compact('jobs'));
    }

In the view:



There is a problem of generating two typical pages: /job and /job?page=1 the two page has the same contents.

I want to do anything that removes the query string page from the first page of the pagination.

I have tried the following:

if ($jobs->onFirstPage()){
  $jobs->setPageName('');
} 

But this corrupt the pagination, i.e the links of pages does not load correctly and the query string value remains for all pages.



via SaidbakR

Advertisement