Laravel 6 Create Custom Exception Error Page Example

Today, We want to share with you Laravel 6 Create Custom Exception Error Page Example.In this post we will show you Laravel 6 – How to create custom error page with example, hear for laravel error handling best practices we will give you demo and example for implement.In this post, we will learn about Laravel 6.2 Exceptions: How to Catch, Handle and Create Your Own with an example.

Laravel 6 Create Custom Exception Error Page Example

There are the Following The simple About Laravel 6.2 – Custom Error Pages Full Information With Example and source code.

As I will cover this Post with live Working example to develop Create a default error page with Laravel 6, so the How To Create Custom 404 Page In Laravel 6 is used for this example is following below.

Setp 1. HTTP Status Codes for You Basic Knowladge

Laravel 6.2 Exceptions: How to Catch, Handle and Create Your Own,

$http_status_codes = array(
    100 => 'Continue',
    101 => 'Switching Protocols',
    102 => 'Processing',
    200 => 'OK',
    201 => 'Created',
    202 => 'Accepted',
    203 => 'Non-Authoritative Information',
    204 => 'No Content',
    205 => 'Reset Content',
    206 => 'Partial Content',
    207 => 'Multi-Status',
    208 => 'Already Reported',
    226 => 'IM Used',
    300 => 'Multiple Choices',
    301 => 'Moved Permanently',
    302 => 'Found',
    303 => 'See Other',
    304 => 'Not Modified',
    305 => 'Use Proxy',
    306 => 'Switch Proxy',
    307 => 'Temporary Redirect',
    308 => 'Permanent Redirect',
    400 => 'Bad Request',
    401 => 'Unauthorized',
    402 => 'Payment Required',
    403 => 'Forbidden',
    404 => 'Not Found',
    405 => 'Method Not Allowed',
    406 => 'Not Acceptable',
    407 => 'Proxy Authentication Required',
    408 => 'Request Timeout',
    409 => 'Conflict',
    410 => 'Gone',
    411 => 'Length Required',
    412 => 'Precondition Failed',
    413 => 'Request Entity Too Large',
    414 => 'Request-URI Too Long',
    415 => 'Unsupported Media Type',
    416 => 'Requested Range Not Satisfiable',
    417 => 'Expectation Failed',
    418 => 'I\'m a teapot', 
    419 => 'Authentication Timeout',
    420 => 'Enhance Your Calm', 
    420 => 'Method Failure', 
    422 => 'Unprocessable Entity', 
    423 => 'Locked', 
    424 => 'Failed Dependency', 
    424 => 'Method Failure', 
    425 => 'Unordered Collection', 
    426 => 'Upgrade Required', 
    428 => 'Precondition Required',
    429 => 'Too Many Requests', 
    431 => 'Request Header Fields Too Large', 
    444 => 'No Response', 
    449 => 'Retry With', 
    450 => 'Blocked by Windows Parental Controls',
    451 => 'Redirect', 
    451 => 'Unavailable For Legal Reasons', 
    494 => 'Request Header Too Large', 
    495 => 'Cert Error', 
    496 => 'No Cert',
    497 => 'HTTP to HTTPS',
    499 => 'Client Closed Request',
    500 => 'Internal Server Error',
    501 => 'Not Implemented',
    502 => 'Bad Gateway',
    503 => 'Service Unavailable',
    504 => 'Gateway Timeout',
    505 => 'HTTP Version Not Supported',
    506 => 'Variant Also Negotiates', 
    507 => 'Insufficient Storage', 
    508 => 'Loop Detected',
    509 => 'Bandwidth Limit Exceeded',
    510 => 'Not Extended', 
    511 => 'Network Authentication Required', 
    598 => 'Network read timeout error', 
    599 => 'Network connect timeout error',
);

Step 2. Create a simple Laravel 404 View File

resources/views/errors/404.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Sorry - Page Not Found</title>
</head>
<body>
<h3>Fix Error - Comming Soon....</h3> 
This is the custom 404 error page.
<p>
We could not find the page you were looking for.
Meanwhile, you may <a href="">return to dashboard</a> or try using the search form.
</p>
            <h3><i class="fa fa-warning text-yellow"></i> Oops! Page not found.</h3>

</body>
</html>

Step 3. Update Exceptions Handler in Laravel 6

app/Exceptions/Handler.php

public function render($request, Exception $live_ex)
{
    if ($this->isHttpException($live_ex)) {
        if ($live_ex->getStatusCode() == 404) {
            return response()->view('errors.' . '404', [], 404);
        }
    }
 
    return parent::render($request, $live_ex);
}

simple checking status code in Laravel 6.2

public function render($request, Exception $live_ex)
{
    if ($this->isHttpException($live_ex)) {
        if ($live_ex->getStatusCode() == 404) {
            return response()->view('errors.' . '404', [], 404);
        }
         
        if ($live_ex->getStatusCode() == 500) {
            return response()->view('errors.' . '500', [], 500);
        }
    }
 
    return parent::render($request, $live_ex);
}

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel 6.2 redirect to 404 page.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   QueryException in laravel 6 Exception Handling
  2.   How to create Controller in Laravel?
  3.   FIX 500 internal server error laravel
  4.   PHP Change Password script using Mysqli
  5.   Laravel autocomplete typeahead search example
  6.   Create Dynamic hide and show Tabs content in Angularjs
  7.   Elementor cpt select Integration
  8.   Vue js Axios File Upload using PHP
  9.   PHP Laravel 5.7 Image Upload with Validation Tutorial Example
  10.   Internal server error with Laravel FIX