bezhansalleh/filament-panel-switch
Installation
composer require bezhansalleh/filament-panel-switch
Publish the config file (if needed):
php artisan vendor:publish --provider="BezhanSalleh\FilamentPanelSwitch\FilamentPanelSwitchServiceProvider"
Register the Plugin
Add to your app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\BezhanSalleh\FilamentPanelSwitch\FilamentPanelSwitchPlugin::make(),
]);
}
First Use Case
config/filament.php (e.g., admin, tenant, api).config/filament-panel-switch.php (customize switcher behavior, icons, or panel labels).make() method and its options (e.g., label, icon, sort).config/filament.php with unique keys.Panel Registration
Define panels in config/filament.php:
'panels' => [
'admin' => [
'path' => 'admin',
'label' => 'Admin Dashboard',
'icon' => 'heroicon-o-home',
],
'tenant' => [
'path' => 'tenant',
'label' => 'Tenant Portal',
'icon' => 'heroicon-o-building-storefront',
],
],
Plugin Configuration
Customize the switcher in FilamentPanelSwitchPlugin::make():
\BezhanSalleh\FilamentPanelSwitch\FilamentPanelSwitchPlugin::make()
->label('Switch Panel')
->icon('heroicon-o-switch-horizontal')
->sortable() // Enable drag-and-drop reordering
->defaultPanel('admin') // Set a default panel
Dynamic Panel Switching Use middleware or middleware groups to restrict access per panel:
// In PanelServiceProvider
$panel->middleware([
\BezhanSalleh\FilamentPanelSwitch\Middleware\RedirectIfNoPanel::class,
]);
Conditional Panel Visibility Hide/show panels based on user roles or features:
->panels([
Panel::make('admin')->visible(fn (User $user) => $user->isAdmin()),
Panel::make('tenant')->visible(fn (User $user) => $user->isTenant()),
])
UrlGenerator to dynamically build panel URLs.__() helper:
'label' => __('filament-panel-switch::panels.admin'),
panel() method in AdminPanelProvider.Panel Key Mismatch
config/filament.php match those referenced in the switcher plugin.config/filament-panel-switch.php under panel_keys.Middleware Conflicts
auth) may break the switcher if not configured correctly.panel() method in AdminPanelProvider to scope middleware:
$panel->middleware([...])->exceptMiddleware([...]);
Caching Issues
php artisan route:clear
Icon/Label Overrides
php artisan vendor:publish --tag=filament-panel-switch-views
APP_DEBUG=true) to log panel-switching events.dd() or dump() to verify the active panel in middleware:
public function handle(Request $request, Closure $next)
{
\Log::info('Active panel:', ['panel' => $request->get('panel')]);
return $next($request);
}
php artisan config:clear if changes to filament-panel-switch.php aren’t applied.Custom Switcher UI Override the default blade view by publishing and modifying:
php artisan vendor:publish --tag=filament-panel-switch-views
Edit resources/views/vendor/filament-panel-switch/....
Dynamic Panel Loading Fetch panels from a database or API:
->panels(fn () => Panel::query()->get()->map(...))
Event Listeners Listen for panel-switch events (e.g., log activity):
\BezhanSalleh\FilamentPanelSwitch\Events\PanelSwitched::class => [
\App\Listeners\LogPanelSwitch::class,
],
API Integration Expose panel-switching via a custom API endpoint:
Route::post('/switch-panel', [PanelSwitchController::class, 'switch']);
How can I help you explore Laravel packages today?