Get "PHP 8 in a Nuthshell" (Now with PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

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 the down 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.

Maintenance mode secret

Learn the fundamentals of PHP 8 (including 8.1, 8.2, 8.3, and 8.4), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-digest guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

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.

Comments?