问题
Every time php artisan down
is turned on, Laravel displays 503 page.
OK. I can customise it by creating new file called 503.blade.php
inside resources/views/errors
.
However I don't consider Maintenance Mode as error at any point despite of the fact that it makes website unavailable for a client as well as despite of consistent description of HTTP 503:
The 503 Service Unavailable error is a server-side error, meaning the problem is usually with the website's server. ... Even though the 503 Service Unavailable error means that there's an error on another computer, the issue is probably only temporary.
How can I define my own blade template (let's say maintenance_mode.blade.php
) to customise what users see during the app down and leave 503 intact?
My efforts: I investigated the middleware itself inside the vendor but it only throws the exception, I assume the exception is being caught somewhere with and handles response with a corresponding view? Can someone point me on how to achieve what I need?
Thanks
回答1:
One way could be to change render method in Exception's Handler. Something like:
// app_path('Exceptions/Handler.php');
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
if ($exception instanceof \Illuminate\Foundation\Http\Exceptions\MaintenanceModeException) {
return response()
->view('maintenance.down', [
'message' => 'Come back later.'
], 200)
->header('Content-Type', 'text/html; charset=utf-8');
}
return parent::render($request, $exception);
}
回答2:
If You want to display custom message in server maintanence(503.blade.php)
Laravel Has the out of box customization
php artisan down --message="We are Upgrading look and feel"
now We are Upgrading look and feel
will be displayed in page while user visiting the page
If You want More customization kindly Look up the package
https://github.com/MisterPhilip/maintenance-mode
If this answer is irrelevnt
or not fixed your problem
kindly comment below so that i can fix that
Hope it helps
Edited
Ok then run the command in your terminal
php artisan vendor:publish
and choose 0
so that it will publish all the views and configs
now open your view folder there will be a errors
folder and you can see the list of error files
provided by laravel
now change as per your customization and run php artisan opt:clear
it will clear all the cache views ,configs
and now try it
by Customising your 503.blade.php
its works fine form me now
you can just view the tutorial of customising 404.blade.php
and customize as per the requirement
Customize 404 in laravel
来源:https://stackoverflow.com/questions/54033125/laravel-5-7-custom-blade-template-for-maintenance-mode-but-not-503-blade-php