mskhoshnazar's avatar

Laravel pagination, bad design maybe?

Hi @JeffreyWay I was struggling with a clean way to render simple or regular pagination based on user's agent type (mobile/desktop), and I'm beginning to think that Laravel got it wrong. paginate and simplePaginate is something that should happen at render time (in blade where we call links()) not in the controller, because it's a presentation thing. Right?

0 likes
18 replies
click's avatar

@mskhoshnazar no it is not only a presentation thing it is also a "query thing". The simple paginate only checks if there is a previous or next page. The "paginate()" does a count of all records to see how many pages and how many records there are in total.

If you only want next/prev in all screen sizes: simplePaginate() If you want next/prev only on mobile but the full version with page numbers on desktops than use: paginate() and with css you hide the page numbers for small screens

1 like
mskhoshnazar's avatar

@click Well then the query part should be separated from presentation part.

The paginator is currently generating all the links, and even the "...", to be rendered later using links. I think the cleaner way is to provide some raw data about the records and then decide what to do with it either in the items object with links and simpleLinks or even in the blade template.

My point is, there should be way more control over how pagination is rendered. For example the addition of onEachSide was a good start. But you still can't control how many pages are shown after the first page and before the last page.

mskhoshnazar's avatar

@jlrdw well for some reason displaying 15 buttons at the bottom of the page in a single line breaks my layout. Even if I use onEachSide(0) it's 9 buttons and it's still a bit too long for smaller displays.

jlrdw's avatar

I guess you did not even bother looking at the link I gave above which addresses that problem.

And

the addition of onEachSide was a good start.

That's always been available, by simply customizing the pagination template if needed.

There is already millions of ways to paginate in laravel, look into the API.

The length aware paginator has endless possibilities and customizations but you have to read the API on it to understand it better.

Sometimes I think I'm the only person who digs into the API to discover more.

But no I know there are others who learn a lot from the API.

mskhoshnazar's avatar

@jlrdw you need to calm down my friend :) I did look at the link you provided. If you read the op again you might see that I'm not looking for a solution or an explanation on how if statements work in php! I'm saying Laravel's implementation of pagination can be improved, and I'll be happy to hear your thoughts about that.

Also, be kind to show me where I suggested a built-in mobile detection. If you didn't manage to find this suggestion, take the time to read my discussion with click.

Cronix's avatar

Maybe you can publish the pagination assets and customize their views, or create your own and use those? You can pass the view to use to the paginator. https://laravel.com/docs/5.8/pagination#customizing-the-pagination-view

At least you can hide some of the buttons for mobile that way by adding the relevant classes to the buttons.

Even if I use onEachSide(0) it's 9 buttons and it's still a bit too long for smaller displays.

I'm not sure what the issue with that is. What if you changed it to just 1 instead of 0? Does changing the number change the links at all?

mskhoshnazar's avatar

@cronix of course we can customize pretty much everything. But as I explained in previous posts, I think data and presentation are not well separated here.

About onEachSide, it just changes the number of links "right next to" the current page. But you have no control over how many links are there after first page and before the last page. So it goes like this:

onEachSide(3) //default
< last 14 13 ... 10 9 8 _7_ 6 5 4 ... 3 2 first >
onEachSide(0)
< last 14 13 ... _7_ ... 3 2 first >
mskhoshnazar's avatar

@jlrdw again, please calm down. as you said, many others dig into the API, and I do too when I need to. This is not about showing off how well we know Laravel API and how we can customize things. It's about improving the out of the box behaviour and making things simpler.

I think mobile detect isn't that active anymore. I'm using https://github.com/jenssegers/agent which is based on mobile detect.

jlrdw's avatar

Wow to expect Taylor to do every possible conceivable thing that everyone could possibly ever conceive of they need. Just wow is all I can think of.

Or roll up your sleeves and program something.

No arguments just saying it's a PHP framework. Seems some things we should do our selves.

But really if having that much trouble there are Consultants you could hire to help you.

I look forward to seeing the issue you raise on this.

mskhoshnazar's avatar

there are Consultants

@jWell I'm glad you're aware of their existence. Maybe they can help you calm down and stop spamming some day.

Cronix's avatar

Just wow is all I can think of.

Us too, but for different reasons.

3 likes
jlrdw's avatar

If you read the op again you might see that I'm not looking for a solution or an explanation on how is statements work in php! I'm saying Laravel's implementation of pagination can be improved, and I'll be happy to hear your thoughts about that.

The link was laravel.

jlrdw's avatar

separating data and presentation

It is separated those links have nothing to do with the data.

My point is you need to learn that.

There is absolutely nothing wrong with the way pagination is right now.

You are free to do those pagination links anyway you see fit.

But I apologize for trying to help and get you to understand that.

Your mind is already locked into there is something wrong with Taylor's pagination but the problem is there is nothing wrong with it.

Cronix's avatar

....can't....stop....digging....this....hole....must....complete....

jlrdw's avatar

Okay I'm done but I was just trying to say in my way there's nothing wrong with the pagination as is right now.

I don't mean to come across strong but I even gave a link showing how you can write a custom template.

The OP somehow I believes that data and pagination is linked, they are not, those links are independent and you can write anyway you want to.

Why is that so hard to understand.

@cronix even if you don't defend my side here, I figured you would at least defend the current paginator.

But that's your choice.

Please or to participate in this conversation.