- How do I quickly enable demo mode for a Laravel app to hide work-in-progress features from clients?
- Install the package via Composer, publish the config, then add the middleware to your `app/Http/Kernel.php`. Configure the `demo_url` (e.g., `/demo`) and `under_construction_url` (e.g., `/under-construction`) in `config/demo_mode.php`. Clients must visit `/demo` first to unlock protected routes.
- Does this package work with Laravel 9+? Are there any version compatibility issues?
- The package supports Laravel 7–9. For Laravel 8+, Spatie recommends using Laravel’s built-in `php artisan down` command instead, as it provides similar functionality. Always check the package’s `composer.json` for exact version constraints before installing.
- Can I restrict demo mode access to specific IPs or routes instead of a demo URL?
- Yes. The package allows IP whitelisting in the config file (`demo_mode.php`). You can also apply the middleware to specific routes or route groups using `Route::middleware(['demo'])` instead of registering it globally in `Kernel.php`.
- What happens if a user visits the demo URL but the middleware is misconfigured? Will they get a 404 or infinite redirect?
- If the demo URL is blocked or misconfigured, the package will redirect users to the `under_construction_url` indefinitely. There’s no built-in fallback to prevent this, so test thoroughly in staging. Ensure the demo URL is accessible and not cached.
- Will this package interfere with Laravel’s route caching (`php artisan route:cache`)?
- Yes, route caching can conflict with dynamic middleware like demo mode. If you cache routes, ensure the demo mode middleware is registered *after* caching or test that the demo URL still grants access. Clear cached routes (`php artisan route:clear`) when toggling demo mode.
- Is this package suitable for API routes (REST/GraphQL) or only web routes?
- The package works for both web and API routes, but API responses (e.g., JSON) will redirect to the `under_construction_url` instead of returning a 403. For APIs, consider combining it with API gateways or custom middleware to handle redirects gracefully.
- How do I test demo mode in a Laravel application? Are there edge cases I should check?
- Test by enabling demo mode, visiting a protected route (should redirect), then accessing the demo URL (should unlock). Check edge cases like cached routes, API calls, and session handling. Use `php artisan route:clear` and test with/without sessions to ensure consistency.
- The package is archived—will it still receive updates? What if I find a bug?
- Since the package is archived (last release in 2023), no official updates are expected. If you encounter issues, fork the repository or check for community forks. For critical needs, consider alternatives like Laravel’s `down` command or custom middleware with active maintenance.
- Can I use this alongside Laravel’s built-in authentication (e.g., Breeze, Sanctum) or does it override it?
- Demo mode operates independently of Laravel’s auth system. It will redirect *all* unauthorized users, including unauthenticated ones. If you need to combine it with auth (e.g., allow logged-in users to bypass demo mode), you’ll need custom logic in the middleware or config.
- What’s the performance impact of using this middleware? Should I benchmark it?
- The middleware adds negligible overhead, as it’s a simple session-based check. Benchmarking is unlikely to show significant slowdowns, but test in your specific environment if performance is critical. The package’s lightweight design makes it suitable for most use cases.