Displaying a personalized message during Laravel’s maintenance mode

With the help of @Ifnot, the answer has been updated to comply with Laravel 8.x.
For displaying a custom message on the server maintenance page (503.blade.php) in Laravel, you can use the out-of-the-box customization. This will display the message when the user visits the page. If you require further customization, you can check out the package. If there are any issues with this solution, please leave a comment below so that it can be fixed. I hope this helps.
Another solution is to use (Int), (Carbon), and (Carbon) for detailed information, beyond just a message, on your maintenance page.


Solution 1:

The “json_decode” step is unnecessary since all of the “error” views, including

503.blade.php

, already contain the variable

$exception

.

By using

{{ $exception->getMessage() }}

in your view, you can obtain the precise value that was initially passed to the

artisan down --message

command.


Solution 2:


The message is not utilized in the 503.blade.php view by default.

The JSON formatted file containing this message can be accessed through the use of the

php artisan down

command and is named

storage/framework/down

.

You can utilize this method to directly access the message in your view.

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

An alternative method is to incorporate the suggested approach from this answer which involves utilizing the

$exception

variable within your view, rather than resorting to other methods, resulting in a cleaner solution.

The middleware, identified as

CheckForMaintanceMode

, retrieves the message and additional information from the file. It then generates a

MaintanceModeException

with the collected data.

Update:
Following the release of Laravel 8, the payload for initiating the

storage/framework/down

command has been modified and no longer incorporates the exception message. Therefore, for Laravel 8 and above, it is recommended to use

{{ $exception->getMessage() }}

instead.


Solution 3:


To obtain comprehensive details about your maintenance page, beyond just a message, you have the option to utilize three codes:

$exception->retryAfter

(Int),

$e->willBeAvailableAt

(Carbon), and

$e->wentDownAt

(Carbon). However, it is important to note that in order to do so, you must ensure that the –retry parameter is set in the artisan command.

Frequently Asked Questions