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

[7.x] Added appends($attributes) method to Eloquent collections #32324

Merged
merged 4 commits into from
Apr 13, 2020
Merged

[7.x] Added appends($attributes) method to Eloquent collections #32324

merged 4 commits into from
Apr 13, 2020

Conversation

jazerix
Copy link
Contributor

@jazerix jazerix commented Apr 10, 2020

Much like the makeVisible($attributes) and makeHidden($attributes) methods, appends($attributes) allows the developer to utilize Laravel's accessors to append specific attributes across an entire eloquent collection.

$collection->append($attribute);

If you wan't to achieve something similar right now, you would have to do something like this:

$collection->each(function($model) {
    $model->append($attribute)
});

Otherwise your only option is to specify the attributes to be appended directly within the model, where it will be appended every time.

The downside here is that you'd have to remove/unset/hide the attribute whenever you don't need that specific one.

As an end user, this method allows me to more quickly choose when certain attributes should be appended.

The method has simply been added to the Collections.php class and should not cause any breaking changes.

@GrahamCampbell GrahamCampbell changed the title appends($attributes) method added to Eloquent Collections. [7.x] Added appends($attributes) method to Eloquent collections Apr 11, 2020
@jazerix
Copy link
Contributor Author

jazerix commented Apr 11, 2020

@GrahamCampbell it should be fixed now, if not can you point me in the direction where I'm going wrong? :)

@taylorotwell taylorotwell merged commit 6f426d6 into laravel:7.x Apr 13, 2020
@d-damien
Copy link

Won't that cause confusion with expected behavior (apppend being synonymous with push) ? Maybe eachAppend instead, like there is eachSpread ?

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.

None yet

4 participants