Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Added updateOrCreate function#63

Open
casenjo wants to merge 1 commit into
bosnadev:masterfrom
casenjo:master
Open

Added updateOrCreate function#63
casenjo wants to merge 1 commit into
bosnadev:masterfrom
casenjo:master

Conversation

@casenjo

@casenjo casenjo commented Dec 9, 2015

Copy link
Copy Markdown

The Repository class is missing a very useful function to be able to create
a model if it doesn't exist, or update it if it does.

The updateOrCreate($attributes, $values) function was added to the
Repository contract and abstract class to account for this.

One of the great functions that Eloquent has is to be able to create
a model if it doesn't exist, or update it if it does.

Calling $model->updateOrCreate($attributes, $values) will search for a
model matching the values in $attributes and if found will update it
with the values in $values. If it wasn't found, then it will create a
model for it. In both situations the instance of that model will be
returned.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant