Maintenance Mode Secrets0:00
All right, let's talk about maintenance mode. So as you know, you can run php artisan down whenever you need to run important updates. However, this functionality has been extended a good bit. So let's bring it back up and have a look at the help. So you'll see a few new things here. Let's start with the secret. So maybe you want maintenance mode for most of the world, but you still want a whitelist for yourself. All right, let's create a secret key. This can be anything you want.
All right, let's create a secret key. This can be anything you want. I'm just going to call it myself, Jeffrey. Okay, so now, if I were to give this a refresh, of course, nobody can access the site. However, as soon as I add the secret as a URI segment, bam, it works. And anywhere I go on the site is going to work, so I don't have to include that secret each time. But yeah, of course, for anyone else, they will continue to see that 503. And really, all Laravel is doing here is it sets a cookie. So we should see...
Why Maintenance Pages Break1:13
Well, here's one thing. Have you ever brought your application down? You then do composer install, and then at some point, you realize this is no longer displaying. Instead, you're seeing an actual error when you load it in the browser. Now the reason for this is because much of Laravel has to boot up in order to check if we're in maintenance mode. So if we're updating all of these dependencies, the likelihood that something will break is very high. So instead, we can have Laravel pre-render the necessary template to avoid this.
Pre-rendering a Maintenance View1:36
very high. So instead, we can have Laravel pre-render the necessary template to avoid this. Once again, have a look. We're going to use the render view. Now to start, this could be your own view or one of the existing error views that Laravel provides. So for example, if I were to create just a plain old view called maintenance. And down here, sorry, back in a minute. If we want to pre-render this view when we bring our application down, let's bring it back up.
If we want to pre-render this view when we bring our application down, let's bring it back up. Try again. But this time, I will say render and then the name of the view. So maintenance. Okay, so now if we come back and refresh, I will see that view. But yeah, of course, if you want to use one of the existing views, that will be in the errors namespace, so to speak. And then usually you do a 503. So 503 is the name of the view for a 503 status, which is service unavailable.
And then usually you do a 503. So 503 is the name of the view for a 503 status, which is service unavailable. And not found. Oops, sorry. Two colons. So that represents the package and the view. Okay, so now give it a refresh. And we're getting the same thing, but it's a little bit different. We've now pre-rendered that view as HTML. And that's what's being displayed here.
Publishing Error Templates2:53
We've now pre-rendered that view as HTML. And that's what's being displayed here. So this will solve that issue where composer install breaks the maintenance page for those visiting your site. And by the way, if you want full control over this, you can run php artisan vendor:publish. And it should be errors. There it is. 12. Okay, so now you have full control over those error templates here. So there's the 503 that we saw.
