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] Allow Model destroy method to accept a collection of ids #25878

Merged
merged 5 commits into from
Oct 3, 2018
Merged

[5.7] Allow Model destroy method to accept a collection of ids #25878

merged 5 commits into from
Oct 3, 2018

Conversation

tristanward
Copy link
Contributor

Currently the destroy() method on an eloquent model accepts both an array of ids to destroy and a list of ids as arguments.

However, if the destroy method is given a Collection of ids (such as from a pluck()) it will destroy only the first id in the collection. This is potentially unexpected behaviour from the developers point of view as no error is seen and an item is removed from the database.

This PR checks the value passed to the destroy() method and if it is an instance of Collection calls the 'all()' method to convert it to an array.

@ahinkle
Copy link
Contributor

ahinkle commented Oct 2, 2018

Can you add a test for this?

@driesvints driesvints changed the title Allow Model destroy method to accept a collection of ids [5.7] Allow Model destroy method to accept a collection of ids Oct 2, 2018
@taylorotwell
Copy link
Member

I don't like to do nested ternarys in the framework.

@tristanward
Copy link
Contributor Author

I've removed the nested ternary and am now doing a separate check for the instance of Collection first.

@taylorotwell taylorotwell merged commit be4cc3b into laravel:5.7 Oct 3, 2018
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.

3 participants