On saving observer.

@param  \Orchestra\Model\Role  $model

@return void
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!");
        }
    }
251899
public function contributeToClass($field, $model)
    {
        parent::contributeToClass($field, $model);

        assert(
            !$model->getMeta()->hasAutoField,
            sprintf(
                "The Models '%s' more than one AutoField, which is not allowed.",
                $this->scopeModel->getMeta()->getNSModelName()
            )
        );

        $this->scopeModel->getMeta()->hasAutoField = true;
        $this->scopeModel->getMeta()->autoField = $this;
    }
167795
public function save(DomainModel $model)
    {
        $this->getEntityManager()->persist($model);
        $this->getEntityManager()->flush();
    }
697570
public function roleSave(Role $role)
    {
        if ($role->role_id) {
            $query = "
                UPDATE
                    auth_role
                SET
                    `name` = :name, description = :description, updated_on = " . $this->sql_time_func . "
                WHERE
                    role_id = :role_id
            ";
        } else {
            $query = "
                INSERT INTO auth_role
                    (name, description, added_on, updated_on)
                VALUES
                    (:name, :description, " . $this->sql_time_func . ", " . $this->sql_time_func . ")
            ";
        }
        $cur = $this->db->prepare($query);
        $cur->bindParam(":name", $role->name, PDO::PARAM_STR, 32);
        $cur->bindParam(":description", $role->description, PDO::PARAM_STR);
        if ($role->role_id) {
            $cur->bindParam(":role_id", $role->role_id, PDO::PARAM_INT);
        }
        $this->db->beginTransaction();
        try {
            $cur->execute();
            if (!$role->role_id) {
                $role->role_id = (int)$this->db->lastInsertId();
            }
            $this->db->commit();
        } catch (PDOException $db_err) {
            $this->db->rollBack();
            if ($this->logger) {
                $this->logger->error("Failed to save role to DB", ['exception' => $db_err]);
            }
            return false;
        }
        foreach ($role->getPermissions() as $permission) {
            // TODO: Something on fail
            $this->rolePermissionAdd($role, $permission);
        }

        return true;
    }
756800
public function save(Language $model): void
    {
        if (!$model->save()) {
            throw new \RuntimeException($this->i18n->t('setrun/sys', 'Saving error'));
        }
    }
419367
public function handleLogoutTryRole(): void
	{
		if (!empty($this->id)) {
			unset($this->session[$this->id]);
			$this->id = null;
		}
		$this->presenter->redirect('this');
	}
1223098
public function storeRolePermission(Role $role, Permission $permission)
    {
        $this->getTable()->insert([
            'role' => $role->getRoleName(),
            'type' => $permission->getType(),
            'action' => $permission->getAction(),
            'resource_type' => $permission->getResourceType(),
            'resource_id' => $permission->getResourceId(),
        ]);

        $this->resetPermissionsCacheForRole($role);
    }
847010
public function run()
    {
        /**
         * @param string $roleName
         */
        $createRole = function ($roleName) {
            (new Model([
                Model::FIELD_ID   => Model::getRoleId($roleName),
                Model::FIELD_NAME => $roleName,
            ]))->saveOrFail();
        };

        $createRole(Model::ENUM_ROLE_ADMIN);
        $createRole(Model::ENUM_ROLE_USER);
    }
561694
public function setRole(string $role) {
		$this->user->role = role::get($role);
		R::store($this->user);
	}
181210
public function save(\Illuminate\Http\Request $request)
    {
        $callback = $this->getCallback();

        if (is_callable($callback)) {
            call_user_func_array($callback, [$this->getModel(), $request]);
        }
    }
525868
public function saved($model)
    {
        $translationRepository = \App::make(TranslationRepository::class);
        $cacheRepository       = \App::make('translation.cache.repository');
        foreach ($model->translatableAttributes() as $attribute) {
            // If the value of the translatable attribute has changed:
            if ($model->isDirty($attribute)) {
                $translationRepository->updateDefaultByCode($model->translationCodeFor($attribute), $model->getRawAttribute($attribute));
            }
        }
        $cacheRepository->flush(config('app.locale'), 'translatable', '*');
    }
1163912
public function handle($model)
    {
        if (! $model -> isUserstamping() || is_null($model -> getUpdatedByColumn())) {
            return;
        }

        $model -> {$model -> getUpdatedByColumn()} = auth() -> id();
    }
1185105
public function deactivateRole($featureName, $roleName)
    {
        $feature = $this->getFeature($featureName);
        $feature->removeRole($roleName);
        $this->saveFeature($feature);
    }
1013271
public function updated(Role $role)
    {
        $oldRole = new Role($role->getOriginal());
        $oldRoleName = $oldRole->snake_case_name;
        $newRoleName = $role->snake_case_name;
        if ($newRoleName != $oldRoleName) {
            $this->updateLanguageTerm($oldRoleName, $newRoleName);
        }
    }
925049
public function save(Model $model)
    {
        $model->setAttribute($this->getMorphType(), $this->morphClass);

        return parent::save($model);
    }
48717
public function setRole($role_id)
    {
        if (!empty($role_id) && $this->policy === Rule::NOINHERIT)
            throw new Exception("Rule::NOINHERIT can not be used in combination with a role");

        if ($role_id instanceof Role)
        {
            $this->role = $role_id;
            $role_id = $role_id->getID();
        }
        elseif (!is_scalar($role_id))
            throw new Exception("Role-ID must be a Role or a scalar");

        if ($role_id !== $this->role_id)
        {
            $this->changed = true;
            $this->role_id = $role_id;
        }
    }
966558
public function creating($model)
    {
        if ($model->accountableEnabled()) {
            $model->{$this->config['column_names']['created_by']} = $this->accountableUserId();
            $model->{$this->config['column_names']['updated_by']} = $this->accountableUserId();
        }
    }