can('manage roles'), 403); if ($role && $role->exists) { $this->role = $role; $this->name = $role->name; $this->description = $role->description ?? ''; } } public function save() { $this->validate([ 'name' => 'required|string|max:50|unique:roles,name' . ($this->role ? ',' . $this->role->id : ''), 'description' => 'nullable|string|max:255', ], [], ['name' => 'nombre', 'description' => 'descripción']); if ($this->role) { // Protected roles can't be renamed if (! in_array($this->role->name, self::PROTECTED_ROLES, true)) { $this->role->name = $this->name; } $this->role->description = $this->description ?: null; $this->role->save(); } else { Role::create([ 'name' => $this->name, 'description' => $this->description ?: null, ]); } app(PermissionRegistrar::class)->forgetCachedPermissions(); session()->flash('message', 'Rol guardado correctamente.'); return $this->redirect(route('admin.roles'), navigate: true); } public function render() { return view('livewire.roles.role-form', [ 'isProtected' => $this->role && in_array($this->role->name, self::PROTECTED_ROLES, true), ]); } }