Laravel displays custom message in maintenance mode

I check Laravel docs for maintenance mode:

https://laravel.com/docs/5.3/configuration#maintenance-mode

When you run the php artisan down command, it will put the application into maintenance mode and return the view 503.blade.php.

It works well, but there is an option that I cannot get to work .. when I do:

 php artisan down --message='Upgrading Database' --retry=60 

I want to display the message in the form, I tried to access the obvious option with {{ $message }} without success, it returns an undefined variable.

My question is: how to access it?

+9
source share
3 answers

By default, the 503.blade.php view does not use this message.

This message is available in the JSON file format named storage/framework/down generated by the php artisan down command .

You can do something like this to access directly the message in your view:

 {{ json_decode(file_get_contents(storage_path('framework/down')), true)['message'] }} 

A cleaner way is to use the $exception variable and include {{ $exception->getMessage() }} in your view as suggested in this answer .

Under the hood, the CheckForMaintanceMode middleware layer reads the message and other data from the file and MaintanceModeException with this data.

+12
source

In fact, you do not need this material โ€œjson_decodeโ€, since all the โ€œerrorsโ€ (including 503.blade.php ) have the variable $exception .

That way you can just use {{ $exception->getMessage() }} in your view, and you will get the exact value that you passed to the artisan down --message .

+29
source

If you need detailed information (not just a message) on the service page, you can also use $exception->retryAfter (Int), $e->willBeAvailableAt (Carbon) and $e->wentDownAt (Carbon). Of course, you need to set the - retry parameter in the artisan command.

+3
source

All Articles