// namespace Illuminate\Database\Eloquent;/**
* Create or update a record matching the attributes, and fill it with values.
*
*@param array $attributes
*@param array $values
*@return \Illuminate\Database\Eloquent\Model
*/publicfunctionupdateOrCreate(array $attributes, array $values=[]){return tap($this->firstOrNew($attributes),function($instance)use($values){$instance->fill($values)->save();});}
updateOrInsert 原始碼部分:
// namespace Illuminate\Database\Query/**
* Insert or update a record matching the attributes, and fill it with values.
*
*@param array $attributes
*@param array $values
*@return bool
*/publicfunctionupdateOrInsert(array $attributes, array $values =[]){if(!$this->where($attributes)->exists()){return$this->insert(array_merge($attributes, $values));}return(bool)$this->take(1)->update($values);}
留言列表