public function scopeReplace($query, array $data, $row = null, $log = false) { $action = empty($row->id) ? 'insert' : 'update'; foreach ($data as $key => $value) { if (is_array($value)) { continue; } if (empty($value) && strstr($key, '_id')) { $value = null; } $row->{$key} = $value; } $row->save(); if ($log) { Log::register($action, $this->getTable(), $row); } return $row; }