← Posts

Use Laravel's Maintenance Mode in Statamic

March 16th, 2020 - 2 min read

Heads up! This post was published a while back, so while some of it might still be good, I can't say for sure it's all accurate. Take it with a pinch of salt!

Now that Statamic is just a package inside a Laravel application, it means you can take advantage of Laravel features.

There's a Laravel feature called Maintenance Mode which means visitors will see a 'site down' message. In this article, I'm going to show you how to use it and how to setup your own custom site down screen.

First, let's understand how it works. Laravel's command line, artisan, comes with two commands. php artisan down and php artisan up. The down command takes the site down and the up command puts the site back up. Simple.

When you take a Laravel app down, it stops users from accessing any pages on the site. However, you may want to override this for a few routes, for example, like the Control Panel.

It's actually really easy to do this. Just open up App\Http\Middleware\CheckForMaintenanceMode.php. It should look like this:

1namespace App\Http\Middleware;
3use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
5class CheckForMaintenanceMode extends Middleware
7 /**
8 * The URIs that should be reachable while maintenance mode is enabled.
9 *
10 * @var array
11 */
12 protected $except = [
13 //
14 ];

To add the Control Panel to our exceptions list, just do something like this:

2 * The URIs that should be reachable while maintenance mode is enabled.
3 *
4 * @var array
5 */
6 protected $except = [
7 '/cp/*',
8 ];

Now you should be able to access the Control Panel while your Laravel app is in maintenance mode.

By default, your visitors will see a screen like this while you maintenance mode turned on.


However, it's likely that you'll want to customise this page to fit in with the site. It's actually really easy to do. Just create a Blade or Antlers view with this filename. resources/views/errors/503.blade.php

Whatever you put in that file will get picked up and used instead of the one Laravel provides.

And that's it - it's really that simple!