Auto-generate maintenance mode secret in Laravel
Maintenance mode is a feature in Laravel that allows you to put your application down for maintenance. It’s a great way to inform your users that the application is down for maintenance and will be back up soon.
Typically, you can enable maintenance mode by running the following command.
php artisan down
This will put your application down for maintenance and will show a 503 error with the message “Service Unavailable” to your users.
Now, if you want to have access to your application while it’s in maintenance mode, you can pass a secret option to the down command like so.
php artisan down --secret="123456"
This will put your application down for maintenance but will allow you to access it by passing the secret as a query parameter in the URL like so.
http://localhost:8000/123456
This way, you can access your application while it’s in maintenance mode.
This is good but in a recent release, Laravel has made this even better. Now, you can auto-generate the
secretfor the maintenance mode by passing the--with-secretoption to thedowncommand so that you don’t have to manually enter the secret yourself.
php artisan down --with-secret
This will generate a URL with a random secret for you and will put your application down for maintenance. You can then access your application using this URL.
👋 Hi there! This is Amit, again. I write articles about all things web development. If you enjoy my work (the articles, the open-source projects, my general demeanour... anything really), consider leaving a tip & supporting the site. Your support is incredibly appreciated!
