ady/maintenance-bundle
Laravel package to manage application maintenance mode with configurable settings, custom views, and request whitelisting. Helps you display branded downtime pages, control access during updates, and toggle maintenance behavior via code or config.
Installation
composer require ady/maintenance-bundle
Add to config/bundles.php:
Ady\MaintenanceBundle\AdyMaintenanceBundle::class => ['all' => true],
First Use Case Enable maintenance mode:
php bin/console ady:maintenance:enable
Disable it:
php bin/console ady:maintenance:disable
Where to Look First
config/packages/ady_maintenance.yaml (default path)src/Command/ in the bundle for customizationtemplates/AdyMaintenanceBundle/ for overriding default viewsConditional Maintenance
Use the isInMaintenance() helper in controllers:
if (\Ady\MaintenanceBundle\Helper\MaintenanceHelper::isInMaintenance()) {
return redirect()->route('maintenance.page');
}
Custom Maintenance Pages Override the default Twig template:
templates/AdyMaintenanceBundle/maintenance.html.twig to your project’s templates/ directory.API Maintenance Mode
Combine with middleware (e.g., MaintenanceMiddleware) to block API routes:
// app/Http/Kernel.php
protected $middlewareGroups = [
'api' => [
// ...
\Ady\MaintenanceBundle\Http\Middleware\MaintenanceMiddleware::class,
],
];
Scheduled Maintenance Use Laravel’s scheduler to enable/disable mode:
* * * * * cd /path-to-project && php artisan ady:maintenance:enable
(Disable via cron or manually.)
isInMaintenance() in webpack.mix.js.if (MaintenanceHelper::isInMaintenance()) {
Queue::pause();
}
.env to toggle maintenance per environment:
MAINTENANCE_MODE=true
Caching Issues
php bin/console cache:clear
X-Maintenance-Mode.Route Leaks
MaintenanceMiddleware is not added to web middleware (unless intentional)./health) to confirm they bypass maintenance.Database Locks
dd(\Ady\MaintenanceBundle\Helper\MaintenanceHelper::isInMaintenance());
try {
$this->call('ady:maintenance:enable');
} catch (\Exception $e) {
Log::error('Maintenance enable failed: ' . $e->getMessage());
}
Custom Logic
Extend the MaintenanceChecker service to add conditions:
// config/packages/ady_maintenance.yaml
services:
Ady\MaintenanceBundle\Checker\MaintenanceChecker:
arguments:
$customCheckers: ['App\Checker\CustomMaintenanceChecker']
Override Templates
maintenance.html.twig to templates/AdyMaintenanceBundle/ and modify.maintenance.json.twig.Multi-Tenant Support Store maintenance status per tenant in a pivot table and modify the checker:
public function isInMaintenance(): bool {
return Tenant::find($this->tenantId)?->isInMaintenance ?? false;
}
templates/ and config/ are in the root. Adjust paths in config/packages/ady_maintenance.yaml if needed.APP_ENV but not MAINTENANCE_MODE by default. Override the checker to use it:
# config/packages/ady_maintenance.yaml
parameters:
ady_maintenance.enabled: '%env(bool:MAINTENANCE_MODE,false)%'
How can I help you explore Laravel packages today?