updateOrCreate() public method

Create or update a record matching the attributes, and fill it with values.
public updateOrCreate ( array $attributes, array $values = [] ) : Model
$attributes array
$values array
return Model
Example #1
0
 /**
  * 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;
     }
 }
Example #2
0
 /**
  * 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 static function updateOrCreate($attributes, $values = array())
 {
     return \Illuminate\Database\Eloquent\Builder::updateOrCreate($attributes, $values);
 }