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

[9.x] Force countBy method in EloquentCollection to return base collection #45663

Merged

Conversation

jnoordsij
Copy link
Contributor

@jnoordsij jnoordsij commented Jan 16, 2023

Currently, the countBy method returns a static instance. However, the returned type is always of the form Collection<array-key, int>, so is never an Eloquent collection (in 'logical' sense). This can cause issues when chained with other collection methods, e.g. when doing something like $foo->countBy('bar')->merge($baz);.

Note: an alternative (and perhaps more accurate?) fix might be to change static to self on the base collection, though this is possibly a breaking change on those extending this class.

@taylorotwell taylorotwell merged commit dc78921 into laravel:9.x Jan 16, 2023
@jnoordsij jnoordsij deleted the fix-database-collection-countby-method branch January 16, 2023 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants