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.5] Add Collection::wrap method #20055

Merged
merged 1 commit into from Jul 14, 2017

Conversation

Projects
None yet
4 participants
@thecrypticace
Contributor

thecrypticace commented Jul 14, 2017

If the given value is not a collection, wrap it in one. This is the collection equivalent to Arr::wrap.

If you pass a collection or an array as the value you get a collection with data in the collection or array back. If you pass in anything else you get a collection of one containing that value.

Had the idea while reading the code for PR #20053. It could turn 7 LoC (at the end of setInverseRelation) in that PR to this:

Collection::wrap($models)->each->setRelation($this->inverseSide, $parent);

No more pesky instanceof check! and it reads rather well too.

Add Collection::wrap method
If the given value is not a collection, wrap it in one.

If you pass a collection or an array as the value you get a collection with data in the collection or array back. If you pass in anything else you get a collection of one containing that value.
@decadence

This comment has been minimized.

Show comment
Hide comment
@decadence
Contributor

decadence commented Jul 14, 2017

@taylorotwell taylorotwell merged commit f57b9e2 into laravel:master Jul 14, 2017

2 checks passed

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

This comment has been minimized.

Show comment
Hide comment
@taylorotwell

taylorotwell Jul 14, 2017

Member

I guess I'll merge this because people will just keep sending it. 😬

Member

taylorotwell commented Jul 14, 2017

I guess I'll merge this because people will just keep sending it. 😬

@decadence

This comment has been minimized.

Show comment
Hide comment
@decadence

decadence Jul 14, 2017

Contributor

Haha Taylor can be brute forced :)

Contributor

decadence commented Jul 14, 2017

Haha Taylor can be brute forced :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment