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

[5.7] Make ResourceCollection countable such that it works with count() #26595

Merged
merged 1 commit into from Nov 22, 2018
Merged

[5.7] Make ResourceCollection countable such that it works with count() #26595

merged 1 commit into from Nov 22, 2018

Conversation

@michaeldyrynda
Copy link
Contributor

@michaeldyrynda michaeldyrynda commented Nov 22, 2018

I ran into an issue with a Laravel 5.5 project that I've been upgrading to 5.7 and moving to PHP 7.2.

For consistent representation of my models, I transform them using resources via a presenter and when passing a resource collection to the Blade @each directive, I was hitting a count(): Parameter must be an array or an object that implements Countable error.

This PR makes ResourceCollection implement the Countable interface so that it can be passed straight into @each, which worked fine before the breaking change in 7.2.

@driesvints driesvints changed the title Make ResourceCollection countable such that it works with count() [5.7] Make ResourceCollection countable such that it works with count() Nov 22, 2018
@taylorotwell taylorotwell merged commit 2390252 into laravel:5.7 Nov 22, 2018
2 checks passed
carusogabriel
Copy link
Contributor

carusogabriel commented on 2390252 Nov 25, 2018

@michaeldyrynda These assertions are the same. Please keep one or other.

michaeldyrynda
Copy link
Contributor

michaeldyrynda commented on 2390252 Nov 25, 2018

They're not. If you count($collection) without the Countable interface, it'll return 1. That is why both assertions are there; to verify the behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants