Menu

Laravel HTTP Error Custom Views (404, 403, 500, etc.)
🖼️

Laravel HTTP Error Custom Views (404, 403, 500, etc.)

DEV Community·Rafli Zocky·6 months ago
#v45Fh8NH
#httperror#webdev#laravelblade#php#request
Reading 0:00
15s threshold

How Laravel Handles HTTP Errors

A request hits a non-existent route

Router throws NotFoundHttpException

Exception is caught by Handler

Laravel looks for resources/views/errors/404.blade.php (example)

Returns an HTTP 404 response with the rendered view

Common Handling

app/Exceptions/Handler.php : converts exceptions into HTTP responses.

<?php

namespace App\Exceptions ;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler ; use Illuminate\Http\Exceptions\ThrottleRequestsException ; use Illuminate\Session\TokenMismatchException ; use Illuminate\Auth\Access\AuthorizationException ; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException ; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException ; use Throwable ;

class Handler extends ExceptionHandler { /** * The list of the inputs that are never flashed to the session on validation exceptions.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.