'like', 'email' => 'like', 'status' => '=' ]; /** * @var string */ protected $table = 'users'; protected array $fields = ['id', 'username', 'email', 'avatar', 'creator_id', 'status', 'department_id', 'created_at']; /** * @var array|string[] */ protected array $form = ['username', 'email', 'password', 'department_id']; /** * @var array|string[] */ protected array $formRelations = ['roles', 'jobs']; /** * password * * @return Attribute */ protected function password(): Attribute { return new Attribute( // get: fn($value) => '', set: fn ($value) => bcrypt($value), ); } /** * is super admin * * @return bool */ public function isSuperAdmin(): bool { return $this->{$this->primaryKey} == config('catch.super_admin'); } /** * update * @param $id * @param array $data * @return mixed */ public function updateBy($id, array $data): mixed { if (isset($data['password'])) { if (empty($data['password'])) { if (isset($data['password'])) { unset($data['password']); } } else { $data['password'] = bcrypt($data['password']); } } else{ if (isset($data['password'])){ unset($data['password']); } } return parent::updateBy($id, $data); } }