The name is mostly self-evident. Eloquent has a method called
updateOrCreate()
here: https://laravel.com/docs/5.5/eloquent#other-creation-methods
In some cases, this is really helpful. However, after execution, updateOrCreate()
I need either an updated / created object, or its primary key or its identifier.
Of course, I could do MyModel::where(...)->first()
and provide all this data again, but it is inconvenient and can be expensive.
However, updateOrCreate()
returns true or false .
Any ideas?
source
share