Beto A. Lien
Beto A. Lien

Reputation: 43

Problems with Pagination on Laravel 5.7

I have the next problem

I have a table called employments on mysql, and this table have the column idbusiness that's reference to table business.

Well, My employments are like this

id | idbusiness | name | address

This is the line on my function for pagination:

$employments = employments::paginate(10)->onEachSide(5);

And my code in the showemploymets.blade.php

{{$empleados->appends(request()->except('showemployments'))->links()}}

The problem is when I select the IDBusiness = 1 its ok, show me all the employments from IDBusiness = 1, but when I select the IDBusiness = 2 o 3 o 4

They show me the selected employments up to page XX and not in the first page...

Thanks for your help

Upvotes: 2

Views: 1633

Answers (2)

JoeRoot
JoeRoot

Reputation: 472

Ok so this took me way too long to figure out for Laravel 5.7. This was my error and I hope this helps you out as well.

I'm using nginx as a webserver so this probably only applies to that webserver. It's very important to have this line with the query_string at the end:

try_files $uri $uri/ /index.php?$query_string

I'll post the whole config if you want but this should help you.

Upvotes: 0

kmjadeja
kmjadeja

Reputation: 114

You can try this :

Controller File

public function cities()
{
    $cities = App\City::paginate(2);
    return view('welcome', compact('cities'));
}

Blade File

{{ $cities->onEachSide(3)->links() }}

Description :

onEachSide(1) show the number of pages before and after ACTIVE page.

Output Screenshot

For example consider we are at page 30 we have pagination of 5 and total number of records 355 than:

{{ $cities->onEachSide(1)->links() }}

1 2 .. 29 30 31 .. 66 67


{{ $users->onEachSide(2)->links() }}

1 2 .. 28 29 30 31 32 .. 66 67

Upvotes: 1

Related Questions