What are the differences between updateOrCreate () and updateOrInsert () in laravel 5.4

Both methods seem to create a new record if it does not exist or does not update the record with the data provided

+8
php laravel-5
source share
1 answer

updateOrCreate is an Eloquent Builder method and updateOrInsert is a Query Builder method.

updateOrCreate returns the model, while 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 */ 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 = []) 
+8
source share

All Articles