Save notifications configuration

@param Option $model
175874
public function updated(Option $model)
    {
        $option  = Option::query()->firstOrNew([
            'name' => 'notifications_remove_after_days'
        ]);

        $option->value = input('days');
        return $option->save();
    }
3335
private function doCommitCreate(Model $model)
    {
        $this->dispatchLifecycleEvent(Events::preCreate, $model);

        $this->getPersisterFor($model->getType())->create($model);
        $model->getState()->setNew(false);
        // Should the model always reload? Or should the commit be assumed correct and just clear the new/dirty state?
        $model->reload();

        $this->dispatchLifecycleEvent(Events::postCreate, $model);
        return $model;
    }
550968
public function saving(Eloquent $model): void
    {
        $keyword = Keyword::make($model->getAttribute('name'));

        if ($keyword->searchIn(['guest']) !== false) {
            throw new InvalidArgumentException("Role [{$keyword->getValue()}] is not allowed to be used!");
        }
    }
1341454
public function afterSave(Model $Model, $created, $options = array()) {
		if ($this->settings[$Model->alias]['auto'] === false) {
			return true;
		}
		if (!$Model->ShadowModel) {
			return true;
		}
		if ($created) {
			$Model->ShadowModel->create($Model->data, true);
			$Model->ShadowModel->set($Model->primaryKey, $Model->id);
			$Model->ShadowModel->set('version_created', date('Y-m-d H:i:s'));
			foreach ($Model->data as $alias => $aliasData) {
				if (isset($Model->ShadowModel->_schema[$alias])) {
					if (isset($aliasData[$alias]) && !empty($aliasData[$alias])) {
						$Model->ShadowModel->set($alias, implode(',', $aliasData[$alias]));
					}
				}
			}
			$success = (bool)$Model->ShadowModel->save();
			$Model->versionId = $Model->ShadowModel->id;
			return $success;
		}

		$habtm = array();
		foreach ($Model->getAssociated('hasAndBelongsToMany') as $assocAlias) {
			if (isset($Model->ShadowModel->_schema[$assocAlias])) {
				$habtm[] = $assocAlias;
			}
		}
		$data = $Model->find('first', array('contain' => $habtm, 'conditions' => array($Model->alias . '.' . $Model->primaryKey =>
					$Model->id)));

		$changeDetected = false;
		foreach ($data[$Model->alias] as $key => $value) {
			if (isset($data[$Model->alias][$Model->primaryKey]) && !empty($this->_oldData[$Model->alias]) && isset($this->_oldData[$Model->
				alias][$Model->alias][$key])) {

				$oldValue = $this->_oldData[$Model->alias][$Model->alias][$key];
			} else {
				$oldValue = '';
			}
			if ($value != $oldValue && !in_array($key, $this->settings[$Model->alias]['ignore'])) {
				$changeDetected = true;
			}
		}
		$Model->ShadowModel->create($data);
		if (!empty($habtm)) {
			foreach ($habtm as $assocAlias) {
				if (in_array($assocAlias, $this->settings[$Model->alias]['ignore'])) {
					continue;
				}
				$oldIds = Hash::extract($this->_oldData[$Model->alias], $assocAlias . '.{n}.id');
				if (!isset($Model->data[$assocAlias])) {
					$Model->ShadowModel->set($assocAlias, implode(',', $oldIds));
					continue;
				}
				$currentIds = Hash::extract($data, $assocAlias . '.{n}.id');
				$idChanges = array_diff($currentIds, $oldIds);
				if (!empty($idChanges)) {
					$Model->ShadowModel->set($assocAlias, implode(',', $currentIds));
					$changeDetected = true;
				} else {
					$Model->ShadowModel->set($assocAlias, implode(',', $oldIds));
				}
			}
		}
		unset($this->_oldData[$Model->alias]);
		if (!$changeDetected) {
			return true;
		}
		$Model->ShadowModel->set('version_created', date('Y-m-d H:i:s'));
		$Model->ShadowModel->save();
		$Model->versionId = $Model->ShadowModel->id;
		if (is_numeric($this->settings[$Model->alias]['limit'])) {
			$conditions = array('conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id));
			$count = $Model->ShadowModel->find('count', $conditions);
			if ($count > $this->settings[$Model->alias]['limit']) {
				$conditions['order'] = $Model->alias . '.version_created ASC, ' . $Model->alias . '.version_id ASC';
				$oldest = $Model->ShadowModel->find('first', $conditions);
				$Model->ShadowModel->id = null;
				$Model->ShadowModel->delete($oldest[$Model->alias][$Model->ShadowModel->primaryKey]);
			}
		}
		return true;
	}
276217
public function onCustomFieldCreateOrEdit(Model $model)
    {
        $this->onList();
        Breadcrumbs::register('customfields-create-update', function($breadcrumbs) use($model) {
            $breadcrumbs->parent('customfields');
            $name = $model->exists ? 'Update custom field ' . $model->name : 'Create custom field';
            $breadcrumbs->push($name, '#');
        });

        view()->share('breadcrumbs', Breadcrumbs::render('customfields-create-update'));
    }
520945
public function addEncryptionHook($model)
    {
        // If model is saved, encrypt password
        $t = $this;
        if (isset($model->has_encryption_hook) && $model->has_encryption_hook) {
            return;
        }
        $model->has_encryption_hook = true;
        $model->addHook('beforeSave', function ($m) use ($t) {
            if ($m->isDirty($t->password_field) && $m[$t->password_field]) {
                $m[$t->password_field] = $t->encryptPassword($m[$t->password_field], $m[$t->login_field]);
            }
        });
    }
1017457
protected function config($option, $model)
    {
        return Arr::get($this->config, "loggable.$model.$option")
               ?: Arr::get($this->config, $option);
    }
824966
public function save(Model $model)
    {
        $saved = $model->save();

        if ($saved) {
            app('cache')->flush();
        }

        return $saved;
    }
589661
public function onPreviewHtmlReport(Model $model)
    {
        $this->onReportsHistory();
        Breadcrumbs::register('logger-reports-preview-' . $model->id, function($breadcrumbs) use($model) {
            $breadcrumbs->parent('logger-reports-history');
            $breadcrumbs->push('Preview report ' . $model->name, handles('antares::logger/view/' . $model->id));
        });
        view()->share('breadcrumbs', Breadcrumbs::render('logger-reports-preview-' . $model->id));
    }
6989
protected function initWidgets($model)
    {
        $config = $model->getFieldConfig();
        $config->model = $model;
        $config->arrayName = class_basename($model);
        $config->context = 'update';

        $widget = $this->makeWidget('Backend\Widgets\Form', $config);
        $widget->bindToController();
        $this->formWidget = $widget;
    }
481453
public function setModel(Model $model)
    {
        $this->model = $model;
        $this->fm = $this->model->loadFunctionMap();
    }
281282
protected function config($option, $model = null)
    {
        if ($value = $this->config["chronos.override.$model.$option"]) {
            return $value;
        }

        $value = $this->config["chronos.merge.$model.$option"];

        if (is_array($value)) {
            return array_merge($this->config["chronos.$option"], $value);
        }

        if (is_null($value)) {
            return $this->config["chronos.$option"];
        }

        return $value;
    }
1089174
public function markSaved($model)
    {
        $hash = spl_object_hash($model);

        if (isset($this->pending[$hash])) {
            unset($this->pending[$hash]);
        }

        $this->saved[$hash] = $model;
    }
188783
public function save(Model $model)
    {
        $this->setForeignAttributesForCreate($model);

        return $model->save() ? $model : false;
    }
1148015
public function submit( $model, $notify = true, $config = [] ) {

		if( !$model->isSubmitted( true ) && $model->isSubmittable() ) {

			$model = $this->updateStatus( $model, IApproval::STATUS_SUBMITTED );

			if( $notify ) {

				$title = ucfirst( self::$parentType ) . ' - ' . $model->getClassName() . ' - Submitted';

				$config[ 'template' ] = $config[ 'template' ] ?? CoreGlobal::TPL_NOTIFY_STATUS_SUBMIT;

				$this->notifyAdmin( $model, $config, $title );
			}

			return $model;
		}

		return false;
	}
530235
public function confirm( $model, $notify = true, $config = [] ) {

		if( !$model->isConfirmed( true ) ) {

			$model = $this->updateStatus( $model, IApproval::STATUS_CONFIRMED );

			if( $notify ) {

				$title = ucfirst( self::$parentType ) . ' - ' . $model->getClassName() . ' - Confirmed';

				$config[ 'template' ] = CoreGlobal::TPL_NOTIFY_STATUS_CONFIRM;

				$this->notifyUser( $model, $config, $title );
			}

			return $model;
		}

		return false;
	}
1263730
protected function handleEventsLogging($model)
    {
        if (config($this->package.'.log_events_to_file') === true) {
            $this->logEventsToFile($model);
        }

        if (config($this->package.'.log_events_to_db') === true) {
            $this->logEventsToDB($model);
        }
    }