Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.x] force Eloquent\Collection::partition to return a base Collection #53304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Oct 25, 2024

  1. force Eloquent\Collection::partition to return a base Collection

    the way `partition` currently works is it returns an `Eloquent\Collection` of `Eloquent\Collection`s, which is technically not allowed by the generic type hints defined by the class, and also doesn't really make any logical sense for how someone would want to use this.
    
    It also causes issues in the IDE because based on the type hints it assumes ALL values of an `Eloquent\Collection` are of type `Eloquent\Model`, which is not the case for the `partition` method.
    
    what we really want is a `Support\Collection` of `Eloquent\Collection`s. we can accomplish this by first calling the `parent::partition` method to get our (illegal) result of `Eloquent\Collection<int, Eloquent\Collection>`, and then converting it to a base collection to end up with the desired `Support\Collection<int, Eloquent\Collection>`.
    browner12 committed Oct 25, 2024
    Configuration menu
    Copy the full SHA
    54b0ac3 View commit details
    Browse the repository at this point in the history