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

Added push() method #648

Closed
wants to merge 1 commit into from
Closed

Added push() method #648

wants to merge 1 commit into from

Conversation

Plytas
Copy link
Contributor

@Plytas Plytas commented Jan 24, 2024

I was looking for a fluent way to add items to collection but wasn't able to find one.
Current alternatives:

SimpleData::collection()->toCollection()->push('foo'); //Technically works if underlying collection is `\Illuminate\Support\Collection`, but cannot be properly type hinted because `$items` is `\Illuminate\Support\Enumerable`.
$collection = SimpleData::collection();
$collection[] = 'foo'; //This works because `DataCollection` implements `ArrayAccess`

This proposed method is the same as \Illuminate\Support\Collection::push().

@rubenvanassche
Copy link
Member

In v4 these methods are deprecated since we want to move away from DataCollections to regular Collections, we're not going to add any extra methods in such case just use a Collection from now on.

@Plytas
Copy link
Contributor Author

Plytas commented Feb 9, 2024

Wasn't aware of upcoming v4 changes and I see it has been tagged recently. Thank you!

@rubenvanassche
Copy link
Member

Yeah has been in the making for a year, glad I've could finally release it 😄

I hope to completely remove DataCollection in v5 but that requires some extra thinking about how to handle a few scenarios, that's something for the next weeks.

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