Custom error pages for Laravel Nova, provided as a small middleware package.
- Package:
next-tecnology/nova-custom-errors - PHP: ^8.2 | ^8.3 | ^8.4
- Nova: ^4.0 | ^5.0
composer require next-tecnology/nova-custom-errorsThe service provider is auto-discovered via Composer; no manual registration is needed.
Edit config/nova.php and add the middleware to Nova's middleware stack. Place it after the standard Nova middleware so it can intercept responses and render the appropriate error views.
// config/nova.php
return [
// ...
'middleware' => [
'web',
.....
\NextTecnology\NovaCustomErrors\Http\Middleware\HandleNovaErrors::class,
.....
],
// ...
];That’s it. The middleware will check the response status code and, if it is greater than 400, attempt to render a matching view from this package.
By default, the package ships with views that are used immediately without any publishing. If you want to customize them, publish the views to your application and edit them as needed:
php artisan vendor:publish \
--provider="NextTecnology\\NovaCustomErrors\\NovaCustomErrorsServiceProvider" \
--tag="nova-custom-errors-views"This will copy the views to:
resources/views/vendor/nova-custom-errors/
Available default views in the package:
401.blade.php402.blade.php403.blade.php404.blade.php419.blade.php429.blade.php500.blade.php503.blade.php
The middleware looks up views by status code using the namespace nova-custom-errors::. For example, a 404 response will try to render nova-custom-errors::404 (or your published override at resources/views/vendor/nova-custom-errors/404.blade.php).
The middleware HandleNovaErrors inspects the response returned by Nova and, for status codes > 400, tries to render a view named after that status code:
$view = 'nova-custom-errors::' . $response->getStatusCode();
if (view()->exists($view)) {
return response()->view($view);
}If no matching view exists, the original response is returned unchanged.
- Trigger a known error within Nova (e.g., visit a non-existent Nova resource) and you should see the corresponding custom error page.
- If you customized views, ensure your edited versions appear under
resources/views/vendor/nova-custom-errors/.
- "Class not found" for the middleware: run
composer dump-autoloadand ensure the fully-qualified class name is correct:\\NextTecnology\\NovaCustomErrors\\Http\\Middleware\\HandleNovaErrors::class. - View not found: ensure the view exists in the package (it does by default), or, if you published views, confirm they are under
resources/views/vendor/nova-custom-errors/with the correct filename (e.g.,404.blade.php). - Config cache: after changing
config/nova.php, runphp artisan config:clear.
MIT
The bundled minimal layout view (resources/views/vendor/nova-custom-errors/minimal.blade.php after publishing, or the package view resources/views/minimal.blade.php) includes this line:
@vite(['resources/css/app.css', 'resources/js/app.js'])This expects Laravel Vite to build your assets into public/build (the default). If those files are not available in your project, you have two options:
- Provide the assets via Vite (recommended)
- Install dependencies and build once for production:
This will produce the
npm install npm run build
public/builddirectory and the@vitedirective will work. - Or run the Vite dev server during local development:
Ensure your app is configured to connect to the Vite dev server as usual for your Laravel version.
npm run dev
- Customize the layout to fit your asset pipeline
- Publish the views if you haven’t already:
php artisan vendor:publish \ --provider="NextTecnology\\NovaCustomErrors\\NovaCustomErrorsServiceProvider" \ --tag="nova-custom-errors-views"
- Then edit
resources/views/vendor/nova-custom-errors/minimal.blade.phpand either remove the@vite(...)line or replace it with whatever your project uses (CDN, compiled static files, Mix, etc.). For example:<!-- Replace Vite with direct files or CDN as needed --> <link rel="stylesheet" href="/css/app.css"> <script src="/js/app.js" defer></script>
If your project doesn’t need any custom CSS/JS for these error pages, you can safely remove the @vite([...]) line.