Both methods seem to create a new record if not existed or update a record with provided data. Whats the difference between the two?
updateOrCreate is method of Eloquent Builder and updateOrInsert is method of Query Builder.
updateOrCreate returns model, whereas updateOrInsert returns boolean
Signatures from Laravel code:
updateOrCreate
/** * Create or update a record matching the attributes, and fill it with values. * * @param array $attributes * @param array $values * @return \Illuminate\Database\Eloquent\Model|static */ public function updateOrCreate(array $attributes, array $values = []) updateOrInsert
/** * Insert or update a record matching the attributes, and fill it with values. * * @param array $attributes * @param array $values * @return bool */ public function updateOrInsert(array $attributes, array $values = [])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With