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

Conversation

Projects
None yet
3 participants
@michaeldyrynda
Contributor

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 from Make ResourceCollection countable such that it works with count() to [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

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@carusogabriel

This comment has been minimized.

Contributor

carusogabriel commented on tests/Integration/Http/ResourceTest.php in 2390252 Nov 25, 2018

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

This comment has been minimized.

Contributor

michaeldyrynda replied 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