hasRole('Admin')) { abort(403); } $this->roles = Role::all(); $this->loadUsers(); } public function loadUsers() { $this->users = User::with('roles')->orderBy('name')->get(); } public function updateRole($userId, $roleName) { $user = Auth::user(); if (!$user->hasRole('Admin')) { session()->flash('error', 'Solo administradores.'); return; } $targetUser = User::findOrFail($userId); if ($targetUser->id === $user->id && $targetUser->hasRole('Admin')) { session()->flash('error', 'No puedes cambiarte el rol a ti mismo.'); return; } $targetUser->syncRoles([$roleName]); $this->loadUsers(); $this->dispatch('notify', 'Rol actualizado.'); } public function render() { return view('livewire.admin-users'); } }