Making maintenance mode of our application is a common task when we need to update our application and check it is working or not by not showing others until it is working perfectly. When we make our application down with artisan down command, it will down the application for all even you. In this situation, Laravel gives you a secret route for maintenance bypass which help you to bypass the maintenance mode only for you and the rest of the world get it in maintenance mode. It supports from Laravel 8 but here I'll also show you how you can use the secret route maintenance mode bypass in Laravel 6, Laravel 7 by haruncpi/laravel-maintenance package.
It's very easy to make available your application only for you or your team when it's in maintenance mode. After down the site with a secret you can easily access your site and can share the secret route to your team to get access to your site when it's maintenance mode. Where IP whitelisting is a little bit complex and real IP is not available for every developer.
From laravel 8, it's by default support maintenance mode bypass with the secret route. If you are using Laravel 8 or latest version then you don't need to install anything. Just check the usage section.
If you want to add a secret route for maintenance mode bypass in your Laravel 6, Laravel 7 then install the haruncpi/laravel-maintenance package.
composer require haruncpi/laravel-maintenance
Now change the default maintenance middleware in app/Http/Kernel.php
file.
//\App\Http\Middleware\CheckForMaintenanceMode::class,
\Haruncpi\LaravelMaintenance\Middleware\MaintenanceMode::class,
Enable maintenance mode with the secret route for maintenance mode bypass.
php artisan down --secret="mysecretkey"
Note Set a secret key for bypass the maintenance for you. Choose a complex key for better security.
With the help of secret route maintenance mode bypass, now you can access your site by given URL and the rest of the world will get it in maintenance mode until you make it up by php artisan up
command.
http://example.com/mysecretkey
Here mysecretkey
will be the given key which you used in artisan down command.
Hope this post will help you to learn about Laravel secret route for maintenance mode bypass. If you like this post, please share it with others.