Comments (5)
I think only positive values should be supported, as the others don't make much sense.
Also I think the ability you suggested to "paginate backwards" wouldn't be very useful, but may be source of confusion:
- not the same at taking the last page (with your example, {8,9,10} vs. {10})
- order of items: forward, backward?
On the other hand, I may suggest a method countPages
which could be used as so:
$perPage = 16;
$numPages = $collection->countPages($perPage);
// first page
$collection->forPage(1, $perPage);
// last page
$collection->forPage($numPages, $perPage);
from ideas.
@vlakoff For current behavior, If I call 0 to return the lastPage. I can get the last page without count the $numPages
//last page
$collection->forPage(0, $perPage);
from ideas.
Nope:
$collection = collect([1,2,3,4,5,6,7,8,9,10]);
// last page is #4 and contains [10]
$collection->forPage(4, 3);
// [8,9,10]
$collection->forPage(0, 3);
Also, this behavior is because internally array_slice
is called with offset ($page - 1) * $perPage
. So with page 1 we get offset 0 which is fine, but with page <= 0 we get a negative offset and that is unsuitable.
from ideas.
@vlakoff sorry I misunderstood here. You are right. The last page is 10 .
So I can not get the last page like that => Maybe It also makes us confused here.
from ideas.
Dear,@chungth I noob to laravel.Kindly guide me on collection forPage().And what its functionality.Is not it query from Model(DB).Means its load all the data atonce and gives us data on each request or something else.Kindly guide me.
from ideas.
Related Issues (20)
- [Proposal] Easy way to cancel notifications at time of sending
- Rendering Blade Components Outside of Views HOT 1
- Assert that a component has rendered on a page
- Service Container | Contextual Binding of the Methods
- [REQUEST] Enable flush method from dynamoDB cache HOT 3
- [Feature] Enable flush method from dynamoDB
- [Proposal] Support AOP with php8 Attribute
- laravel join select max of joined column
- Ability to get event name which fires in Eloquent booted method HOT 1
- Make `php artisan migrate:reset` work with *-schema.dump
- Size File Validation only deals with Kilobytes
- Suggesting that ".env.testing" file be added to .gitignore HOT 2
- add native support for dev containers HOT 3
- [9.x] Rename firstOrNew() to firstOrMake()
- Set property to a config value via an Attribute HOT 1
- Add support to get more information on the job class
- Allow pausing batches
- afterCommit on Queueable Anonymous Event Listeners
- Upsert for related models
- Command option to run scheduler in a particular timezone
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ideas.