Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Panel Switch Laravel Package

bezhansalleh/filament-panel-switch

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require bezhansalleh/filament-panel-switch
    

    Publish the config file (if needed):

    php artisan vendor:publish --provider="BezhanSalleh\FilamentPanelSwitch\FilamentPanelSwitchServiceProvider"
    
  2. Register the Plugin Add to your app/Providers/Filament/AdminPanelProvider.php:

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                \BezhanSalleh\FilamentPanelSwitch\FilamentPanelSwitchPlugin::make(),
            ]);
    }
    
  3. First Use Case

    • Define multiple panels in config/filament.php (e.g., admin, tenant, api).
    • Access the switcher via the Filament dashboard sidebar (default location).
    • Click to toggle between registered panels.

Where to Look First

  • Config File: config/filament-panel-switch.php (customize switcher behavior, icons, or panel labels).
  • Plugin Documentation: Focus on the make() method and its options (e.g., label, icon, sort).
  • Panel Registration: Ensure panels are properly defined in config/filament.php with unique keys.

Implementation Patterns

Core Workflow

  1. 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',
        ],
    ],
    
  2. 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
    
  3. Dynamic Panel Switching Use middleware or middleware groups to restrict access per panel:

    // In PanelServiceProvider
    $panel->middleware([
        \BezhanSalleh\FilamentPanelSwitch\Middleware\RedirectIfNoPanel::class,
    ]);
    
  4. 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()),
    ])
    

Integration Tips

  • Authentication Sync: Use Filament’s built-in auth to ensure users can’t access unauthorized panels.
  • URL Handling: Leverage Filament’s UrlGenerator to dynamically build panel URLs.
  • Localization: Translate panel labels via Filament’s __() helper:
    'label' => __('filament-panel-switch::panels.admin'),
    
  • Testing: Mock the switcher in tests by overriding the panel() method in AdminPanelProvider.

Gotchas and Tips

Pitfalls

  1. Panel Key Mismatch

    • Ensure panel keys in config/filament.php match those referenced in the switcher plugin.
    • Fix: Validate keys in config/filament-panel-switch.php under panel_keys.
  2. Middleware Conflicts

    • Applying panel-specific middleware (e.g., auth) may break the switcher if not configured correctly.
    • Fix: Use panel() method in AdminPanelProvider to scope middleware:
      $panel->middleware([...])->exceptMiddleware([...]);
      
  3. Caching Issues

    • Filament’s route caching may not reflect panel changes immediately.
    • Fix: Clear routes after adding/removing panels:
      php artisan route:clear
      
  4. Icon/Label Overrides

    • Custom icons/labels in the switcher may not update if cached assets are stale.
    • Fix: Publish and update the plugin’s views:
      php artisan vendor:publish --tag=filament-panel-switch-views
      

Debugging Tips

  • Check Logs: Enable debug mode (APP_DEBUG=true) to log panel-switching events.
  • Inspect Requests: Use Laravel’s 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);
    }
    
  • Verify Config: Run php artisan config:clear if changes to filament-panel-switch.php aren’t applied.

Extension Points

  1. 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/....

  2. Dynamic Panel Loading Fetch panels from a database or API:

    ->panels(fn () => Panel::query()->get()->map(...))
    
  3. Event Listeners Listen for panel-switch events (e.g., log activity):

    \BezhanSalleh\FilamentPanelSwitch\Events\PanelSwitched::class => [
        \App\Listeners\LogPanelSwitch::class,
    ],
    
  4. API Integration Expose panel-switching via a custom API endpoint:

    Route::post('/switch-panel', [PanelSwitchController::class, 'switch']);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver