shamarkellman/advanced-maintenance
Installation:
composer require shamarkellman/advanced-maintenance
Add the service provider to config/app.php:
Shamarkellman\AdvancedMaintenance\AdvancedMaintenanceServiceProvider::class,
Publish Config & Views:
php artisan vendor:publish --provider="Shamarkellman\AdvancedMaintenance\AdvancedMaintenanceServiceProvider" --force
config/advanced-maintenance.phpresources/views/vendor/advanced-maintenance/Enable Maintenance Mode:
php artisan down --secret=your-secret-key
First Use Case:
config/advanced-maintenance.php to define excluded_routes (e.g., ['admin', 'admin/*']).resources/views/vendor/advanced-maintenance/503.blade.php.Admin/CMS Access During Maintenance:
excluded_routes in advanced-maintenance.php to whitelist admin routes (e.g., ['admin/*']).php artisan down and verifying admin routes remain accessible.Coming Soon Page:
resources/views/vendor/advanced-maintenance/503.blade.php with a custom "Coming Soon" template.@if(config('advanced-maintenance.show_countdown'))) to add dynamic elements like countdowns.Dynamic Route Whitelisting:
// app/Http/Kernel.php
'web' => [
\Shamarkellman\AdvancedMaintenance\Middleware\Maintenance::class,
// Other middleware...
],
authorize() method in the Maintenance middleware (if extended) to add logic (e.g., IP-based access).Environment-Specific Config:
// config/advanced-maintenance.php
'enabled' => env('MAINTENANCE_MODE', false),
php artisan down --secret=$(MAINTENANCE_SECRET)
Integration with Deployment:
deploy:post in Laravel Forge/Envoyer or CI/CD pipelines to enable maintenance mode before updates:
php artisan down --secret=$MAINTENANCE_SECRET --message="Site under maintenance"
Route Caching Conflicts:
php artisan route:cache, ensure excluded_routes are updated before caching:
php artisan route:clear # Clear cache if routes change
Middleware Order Matters:
Maintenance middleware before auth middleware in Kernel.php to avoid redirect loops for excluded routes.Secret Key Security:
--secret flag is required for down commands. Store it in .env:
MAINTENANCE_SECRET=your-strong-secret-here
View Override Pitfalls:
503.blade.php extends the base layout or includes necessary CSS/JS. Example:
@extends('layouts.app')
@section('content')
<h1>Coming Soon!</h1>
<!-- Custom content -->
@endsection
Laravel 8+ Compatibility:
app()->runningInConsole() checks in custom logic.Check Excluded Routes:
dd() in the middleware to verify routes are being excluded:
// app/Http/Middleware/Maintenance.php (if extended)
public function handle($request, Closure $next)
{
dd($this->isExcluded($request)); // Debug exclusion logic
return $next($request);
}
Log Maintenance Events:
\Log::info('Maintenance mode enabled for IP: ' . $request->ip());
Test Locally:
php artisan down --secret=test and test excluded routes in a local environment before deploying.Custom Middleware Logic:
Maintenance middleware to add dynamic exclusions (e.g., user roles):
// app/Http/Middleware/CustomMaintenance.php
public function handle($request, Closure $next)
{
if (auth()->check() && auth()->user()->isAdmin()) {
return $next($request);
}
return parent->handle($request, $next);
}
API Endpoints:
'excluded_routes' => [
'api/*',
],
Kernel.php:
'api' => [
\Shamarkellman\AdvancedMaintenance\Middleware\Maintenance::class,
'throttle:60',
],
Countdown Functionality:
503.blade.php using JavaScript:
<script>
const launchDate = new Date("{{ config('advanced-maintenance.launch_date') }}").getTime();
const countdown = setInterval(() => {
const now = new Date().getTime();
const distance = launchDate - now;
// Update DOM with days/hours/minutes
}, 1000);
</script>
launch_date in advanced-maintenance.php:
'launch_date' => '2023-12-31',
Multi-Language Support:
503.blade.php:
@lang('messages.coming_soon')
resources/lang/en/messages.php:
return [
'coming_soon' => 'We will be back soon!',
];
How can I help you explore Laravel packages today?