config = $config; $this->DBGroup = $this->config->dbProfile; parent::__construct(); $this->table = $this->config->dbTablePerms; $this->tempUseSoftDeletes = $this->config->dbSoftDeletePerms; $this->tempReturnType = $this->config->dbReturnType; $this->validationRules['name'] = 'required|is_unique[' . $this->table . '.name,id,{id}]'; $this->validationMessages = [ 'name' => [ 'required' => lang('Aauth.requiredPermName'), 'is_unique' => lang('Aauth.existsAlreadyPerm'), ], ]; } /** * Checks if perm exist by perm id * * @param integer $permId Perm id * * @return boolean */ public function existsById(int $permId) { $builder = $this->builder(); if ($this->tempUseSoftDeletes === true) { $builder->where($this->deletedField, 0); } $builder->where($this->primaryKey, $permId); return ($builder->countAllResults() ? true : false); } /** * Get perm by perm name * * @param string $name Perm name * * @return boolean */ public function getByName(string $name) { $builder = $this->builder(); if ($this->tempUseSoftDeletes === true) { $builder->where($this->deletedField, 0); } $builder->where('name', $name); if (! $perm = $builder->get()->getFirstRow($this->tempReturnType)) { return false; } return $perm; } }