- How do I enable maintenance mode in Laravel using this package?
- Use the `php artisan maintenance:enable` command to activate maintenance mode immediately. For runtime control, inject the `MaintenanceMode` facade into your code and call `enable()` or `disable()`. The package also supports toggling via a config flag in `config/maintenance.php`.
- Can I customize the maintenance page beyond the default view?
- Yes, the package supports Blade templates. Publish the default view with `php artisan vendor:publish --tag=maintenance-views`, then modify the Blade file in `resources/views/vendor/maintenance`. You can also override the response behavior in the middleware configuration.
- Does this package work with Laravel 7 or older versions?
- The package is designed for Laravel 8+ and may not work out-of-the-box with older versions. Check the `composer.json` constraints or test thoroughly if using Laravel 7 or below, as it relies on newer Laravel features like middleware groups and service container improvements.
- How do I allow specific IPs or users to bypass maintenance mode?
- Configure the `allowed_ips` and `allowed_users` arrays in `config/maintenance.php`. For dynamic allowlists, extend the middleware by overriding the `isAuthorized()` method in the package’s service provider. The package also supports route-based exclusions via middleware groups.
- Will this package interfere with API routes or Sanctum/Passport?
- Yes, the package applies maintenance mode to all routes by default, including API routes. To exclude API routes, add the `maintenance-except` middleware to your API route group in `routes/api.php`. For Sanctum/Passport, ensure the allowed IPs include your auth service’s IP.
- Is there a way to trigger maintenance mode via a webhook or external API?
- The package doesn’t natively support webhook triggers, but you can create a custom route or queue job to call `MaintenanceMode::enable()` when a webhook is received. Alternatively, use Laravel’s task scheduling to toggle maintenance mode at specific times.
- How do I test maintenance mode in a CI/CD pipeline?
- Manually trigger maintenance mode in your tests using `MaintenanceMode::enable()` before assertions. For integration tests, mock the middleware or use Laravel’s HTTP tests to verify responses (e.g., `assertStatus(503)`). Test both allowed and blocked routes to ensure exclusions work.
- What’s the difference between this package and spatie/laravel-maintenance-mode?
- This package is lighter and focuses on simplicity, while `spatie/laravel-maintenance-mode` is more feature-rich (e.g., scheduled maintenance, multi-language support). If you need advanced features like analytics or multi-environment setups, Spatie’s package may be better. For basic toggling and custom pages, this package is a leaner choice.
- Can I use this package in a multi-environment setup (e.g., staging vs. production)?
- Yes, configure environment-specific settings in `config/maintenance.php` using Laravel’s environment variables (e.g., `allowed_ips` for staging vs. production). The package respects Laravel’s `.env` files, so you can toggle maintenance per environment without code changes.
- Does this package support custom HTTP status codes or response formats for APIs?
- By default, it returns a 503 status for web routes and a custom maintenance page. For APIs, override the middleware’s `handle()` method to return JSON responses (e.g., `response()->json(['error' => 'Service Unavailable'], 503)`). The package’s extensible middleware makes this straightforward.