mardi 4 juillet 2017

Laravel 5.4 - Pagination method works wrong?

I've asked a question about the paginate method from laravel cause I couldn't make it to get the output I needed. I wanted to get all records where the name column contains a specific string.

Anyway, what happens is that I get the whole table content + the links are changing immediately:

The little code snippet ( I've tried many different thinks out )

$search = $request['search'];
$usergroups = Usergroups::where('name', 'like', '%' . $search . '%')->paginate(3);

I'm not so sure but I think in my case there is an problem that doesn't come from my code. If I output $usergroups I get this:

current_page    1
data: 
   // my data 
from    1
last_page   2
next_page_url   "http://ift.tt/2umWjsr"
path    "http://blabla.de/test"
per_page    3
prev_page_url   
to  3
total   5

You can clearly see that there is a total of 5 items ( and thats true, I've expected to get 5 items ), and there are 2 pages. Thats also true cause I've set the pagination to paginate(3).

If I output the links in my blade I get something like this:

enter image description here

But if I click on "2" - to get to the last page of that pagination, I don't know why but the links are changing immediately from 1-2 to 1-7.

enter image description here

Without reloading the page or anything.

So before I want to change the pagination link, I get the right amound of items, but if I change to ?page=2, I get all the items in my table. I don't know why but maybe thats a mistake by laravel. I've also tried it with laravel 5.3 ( currently 5.4 ) but got the same problem. If I look into the phpmyadmin query log and manually try the query out, I also get the perfect output. If I use ->get() instead of ->paginate(); I also get the output I want. I have no clue anymore. Maybe anyone knows an answer? Or something I can to? I don't want output my whole table if the user want to search for a specific item

Thanks for any advice and sorry because of my bad english!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2tNXsfS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire