Laravel Server Error Pages
, (*1)
Table of Contents
Errors Avaliables
- 400 Bad Request
- 401 Unauthorized
- 403 Forbidden
- 404 Not Found
- 405 Method not allowed
- 419 Authentication Timeout
- 429 Too Many Requests
- 500 Internal Server Error
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
- Maintenance (used when
php artisan down
)
Languages Avaliables
Installation
Step 1:Install package via Composer, (*2)
composer require enniosousa/server-error-pages
Step 2: If you are using Laravel 5, include the service provider within your config/app.php
file., (*3)
'providers' => [
EnnioSousa\ServerErrorPages\ServerErrorPagesServiceProvider::class,
];
Step 3: Publish vendor provider, (*4)
php artisan vendor:publish --provider="EnnioSousa\ServerErrorPages\ServerErrorPagesServiceProvider"
How to Create Custom Error Pages
Step 1: Create new empty file named with HTTP code error at folder resources/views/errors
like specified in Laravel docs., (*5)
Step 2: Put the following content in the file you just created., (*6)
@include('server-error-pages::template', compact($exception))
Step 3: Add to file resrouces/lang/vendor/en/server-error-pages.php
custom messages following the template:, (*7)
<?php
return [
'000' => [
'title' => "000 HTTP ERROR",
'description' => "Brief description",
'icon' => "fa fa-cogs green", //icon color options are: green, orange or red
'button' => [
'name' => "Try This Page Again",
'link_to' => "reload", //options are: reload, home or previous
],
'why' => [
'title' => "What happened?",
'description' => "Error description"
],
'what_do' => [
'title' => "What can I do?",
'visitor' => [
'title' => "If you're a site visitor",
'description' => "Explanation."
],
'owner' => [
'title' => "If you're the site owner",
'description' => "Explanation"
],
],
],
];
Custom Error Messages
Use abort()
Laravel helper, (*8)
abort(500, "The server is broken");
abort(403, "You user role does not heave permission to see that.");
Or, (*9)
php artisan down --message="This application is update process. Wait 10 minutes and try again." --retry=600