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
secret
for the maintenance mode by passing the--with-secret
option to thedown
command 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.
Like this article?
Buy me a coffee👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.