Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To customize a Laravel HTTP error page, add a status-named Blade template under resources/views/errors/—for example, 404.blade.php for a 404 response. Laravel 12.x also documents broader 4xx and 5xx fallback templates, but 404, 500, and 503 need their own files. These details are based on Laravel 12.x documentation; verify them against your installed version, especially if you use Laravel 13.x.

Choose the right error-rendering approach

Use a status-specific view when the page should depend on the HTTP status, a family fallback when several statuses can share a design, or an exception rendering closure when behavior should depend on a particular exception or request context.

Approach Use it for Where it is configured
Status-specific Blade view A distinct page for an HTTP status such as 404 or 403 resources/views/errors/{status}.blade.php
Status-family fallback A shared page for eligible 4xx or 5xx responses without a matching status-specific page resources/views/errors/4xx.blade.php or 5xx.blade.php
Exception rendering closure Custom handling for a particular exception, potentially varying by request withExceptions in bootstrap/app.php

The fallback behavior and special-status exceptions in this table are documented for Laravel 12.x. Consult the official Laravel 12.x error handling documentation and check the documentation for your installed version before relying on the same behavior elsewhere.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a status-specific error page

  1. Create the view: add a Blade file in resources/views/errors/ named for the status code, such as 404.blade.php, 403.blade.php, or 500.blade.php.
  2. Build the page: add the HTML and Blade markup you want Laravel to render for that status. Laravel 12.x makes the exception available to the view as $exception.
  3. Trigger the status to verify it: Laravel’s abort helper can raise an HTTP exception; for example, abort(404). The exception handler renders the response.

Use $exception only when the page needs information from the exception. Keep visitor-facing text deliberate and avoid exposing internal diagnostic details in a public error page.

Use 4xx and 5xx fallback templates carefully

Laravel 12.x documents 4xx.blade.php and 5xx.blade.php as family fallbacks when a matching status-specific page is absent. The documentation excludes 404, 500, and 503 from these fallbacks because Laravel has dedicated pages for those statuses. To customize any of those three, create its individual status-named view.

Start from Laravel’s published error templates

If you want Laravel’s default error templates as a starting point, run this Artisan command:

php artisan vendor:publish --tag=laravel-errors

After publishing the templates, edit the resulting views to fit your application. The command and template-publishing behavior are documented for Laravel 12.x.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Customize rendering for a particular exception

A status-based view is not always the right fit. In Laravel 12.x, you can register a typed rendering closure inside withExceptions in bootstrap/app.php. Laravel uses the exception type in the closure’s type hint to determine which exception it handles. The closure can return a response such as:

return response()->view('errors.invalid-order', status: 500);

If the closure returns no value, Laravel continues with its default exception rendering. This is useful when one exception requires a different response from other errors that share its HTTP status.

Keep API errors in the expected format

Laravel 12.x chooses HTML or JSON exception rendering based on the request’s Accept header by default. A browser request and an API request therefore should not be assumed to receive the same format: verify the headers your clients send and the response each endpoint expects.

To change the framework’s JSON-rendering decision, Laravel 12.x provides the shouldRenderJsonWhen configuration hook. For example, a rendering closure can check whether a request is under api/*, return a JSON 404 response for that route area, and otherwise return no response so Laravel’s default rendering proceeds. This lets an application vary output by request context instead of forcing every error through an HTML page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check version-specific behavior

The specific fallback rules, publishing command, exception configuration examples, and JSON-rendering behavior above come from Laravel 12.x documentation. That documentation points readers to Laravel 13.x, but the available material does not establish whether every detail is unchanged in 13.x. Check the official documentation for the version installed in your application before applying these instructions.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.