Laravel Secret Maintenance Mode

Most people are aware that Laravel has a nice feature whereby you can place the application into maintenance mode. Maintenance mode is simply a state where should you get any visitors, they will be redirected to a 503 page. This is it in action:

1
2
3
4
5
$ composer create-project laravel/laravel example
...
$ cd example
$ php artisan down
Application is now in maintenance mode.

There is an alternative with Laravel 8, however. Let’s bring the site back up, but then immediately put it back into maintenance mode, but with a secret key.

1
2
3
4
$ php artisan up
Application is now live.
$ php artisan down --secret="ifonlyicouldtell"
Application is now in maintenance mode.

If you go back to the local Laravel site, you will see that it is in maintenance mode. Go to this URL however: http://localhost:8000/ifonlyicouldtell and a special cookie will be placed onto your machine. After that, you can visit any URL you like, but other visitors - the type that don’t know your secret key - will continue to get the 503 page.

Pretty neat, eh?


Hi! Did you find this useful or interesting? I have an email list coming soon, but in the meantime, if you ready anything you fancy chatting about, I would love to hear from you. You can contact me here or at stephen ‘at’ logicalmoon.com