From c76087d14b94cde8646c207565fb34ffa3ab7044 Mon Sep 17 00:00:00 2001 From: Yismen Jorge Date: Sat, 24 Jan 2026 06:35:12 -0400 Subject: [PATCH] Add user access check for panel visibility in PanelSwitch Add the ability to exclude any panel where the user does not pass the canAccessPanel's check --- src/PanelSwitch.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/PanelSwitch.php b/src/PanelSwitch.php index 5a066a5..99a2d07 100644 --- a/src/PanelSwitch.php +++ b/src/PanelSwitch.php @@ -278,6 +278,15 @@ public function getPanels(): array return collect(Filament::getPanels()) ->reject(fn (Panel $panel) => in_array($panel->getId(), $this->getExcludes())) + ->reject(function (Panel $panel) { + $user = auth()->user(); + + if ($user && method_exists($user, 'canAccessPanel')) { + return ! $user->canAccessPanel($panel); + } + + return false; + }) ->when( value: filled($panelIds), callback: function ($panelCollection) use ($panelIds) {