Installation
composer require brickx/maintenance-switch
php artisan vendor:publish --tag="maintenance-switch-config"
config/maintenance-switch.php.Register the Plugin
Add the plugin to your Filament admin panel in app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\Brickx\MaintenanceSwitch\MaintenanceSwitchPlugin::make(),
]);
}
First Use Case
Basic Toggle Integration
render_hook: 'global-search.before').'permissions' => true, // Restrict to users with 'super-admin' role
'role' => 'super-admin',
Secret Token Bypass
.env:
MAINTENANCE_SWITCH_SECRET=your_secure_token_here
'secret' => env('MAINTENANCE_SWITCH_SECRET'),
?secret=your_token to any URL.Dynamic Refresh
'refresh' => true,
Theming & Placement
'icon' => 'heroicon-o-cog', // Use any Heroicon
'tiny_toggle' => true,
render_hook:
'render_hook' => 'navigation.items.after',
Conditional Visibility
if (app()->environment('production')) {
config(['maintenance-switch.permissions' => true]);
}
StatsOverviewWidget) for a unified dashboard.use Brickx\MaintenanceSwitch\Events\MaintenanceModeChanged;
MaintenanceModeChanged::listen(function ($enabled) {
Log::info("Maintenance mode set to: {$enabled}");
});
php artisan vendor:publish --tag="maintenance-switch-views"
Config Overrides
config/maintenance-switch.php take precedence over defaults.php artisan config:clear if changes aren’t reflected.Secret Token Security
config/maintenance-switch.php. Always use .env.php artisan route:clear
Permission Conflicts
permissions: true or role:, verify the Filament user has the correct permissions./filament/admin/debug) for role assignments.Caching Issues
php artisan route:clear
php artisan route:cache
Plugin Registration Order
MaintenanceSwitchPlugin after other plugins that might depend on the navigation structure (e.g., NavigationItems).Toggle Not Showing?
render_hook exists in your Filament panel. Check available hooks in filament-support/src/Resources/Views/Layouts/Navigation/Items.php.'render_hook' => 'global-search.before' as a fallback.Maintenance Page Not Triggering?
APP_ENV is not local (maintenance mode is often disabled locally by default).'secret' => 'test' in config and test with ?secret=test.CSRF Token Errors
web (for CSRF protection).Custom Toggle Logic Override the toggle behavior by extending the plugin:
use Brickx\MaintenanceSwitch\MaintenanceSwitchPlugin;
class CustomMaintenanceSwitch extends MaintenanceSwitchPlugin
{
protected function toggleMaintenanceMode(bool $enabled): void
{
// Custom logic (e.g., log, notify Slack)
parent::toggleMaintenanceMode($enabled);
}
}
Dynamic Secret Tokens Fetch secrets from an API or database:
'secret' => fn() => DB::table('secrets')->where('key', 'maintenance')->value('value'),
Multi-Tenant Support
Scope maintenance mode to tenants by modifying the toggleMaintenanceMode method to check the current tenant:
if (tenant()->is('acme')) {
parent::toggleMaintenanceMode($enabled);
}
Localization Publish translations and extend them:
php artisan vendor:publish --tag="maintenance-switch-translations"
resources/lang/en/maintenance-switch.php:
return [
'toggle_label' => 'Maintenance Mode (Custom Label)',
];
How can I help you explore Laravel packages today?