Coder Social home page Coder Social logo

Comments (5)

vlakoff avatar vlakoff commented on May 3, 2024

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.

chungth avatar chungth commented on May 3, 2024

@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.

vlakoff avatar vlakoff commented on May 3, 2024

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.

chungth avatar chungth commented on May 3, 2024

@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.

RahamSher avatar RahamSher commented on May 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.