fieldSearchable; } /** * Configure the Model **/ public function model() { return Role::class; } /** * @param $input * * @return Role * * @throws \Exception */ public function storeRole($input) { try { DB::beginTransaction(); /** @var Role $role */ $role = Role::create([ 'name' => $input['name'], 'guard_name' => 'web', ]); if (isset($input['permissions'])) { $role->syncPermissions($input['permissions']); } DB::commit(); return $role; } catch (\Exception $e) { DB::rollBack(); throw new UnprocessableEntityHttpException($e->getMessage()); } } /** * @param $input * * @param $role * * @return Role * * @throws \Exception */ public function updateRole($input, $role) { try { DB::beginTransaction(); /** @var Role $role */ $role->update($input); if (isset($input['permissions'])) { $role->syncPermissions($input['permissions']); } else { $role->revokePermissionTo($role->getAllPermissions()); } DB::commit(); return $role; } catch (\Exception $e) { DB::rollBack(); throw new UnprocessableEntityHttpException($e->getMessage()); } } }