public updateOrCreate ( array $attributes, array $values = [] ) : |
||
$attributes | array | |
$values | array | |
return |
public function updateOrCreate(array $attributes, array $values = [])
{
$instance = $this->firstOrNew($attributes);
$instance->fill($values)->save();
return $instance;
}
/** * Store settings in the database. */ public function save() { if ($this->unsaved) { $all = $this->getData(); $data = array_dot($all); foreach ($data as $key => $value) { $this->options->updateOrCreate(compact('key'), compact('key', 'value')); } $this->options->whereNotIn('key', array_keys($data))->delete(); $this->unsaved = false; } }