Laravel5.6 custom 404 error page method

Because laravel frame abnormality is through App \ Exceptions \ Handler class processing, comparison operators may use the instanceof determines whether a specific exception, the render method override class, as follows:

public function render($request, Exception $exception)
{
    / * Error page * /
    if ($exception instanceof NotFoundHttpException) {
        $code = $exception->getStatusCode();
        if (view()->exists('errors.' . $code)) {
            return response()->view('errors.' . $exception->getStatusCode());
        }
    }
    return parent::render($request, $exception);
}

  Then create a directory in the views directory errors in the catalog and then create a 404.blade.php page template, so then there you can use our own custom 404 page when a 404 error!

Guess you like

Origin www.cnblogs.com/huoluobosky/p/11823347.html