Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for How to override laravel nova components
Jenry Mazariegos
Jenry Mazariegos

Posted on • Edited on

     

How to override laravel nova components

Hello again! Before starting the tutorial, you must have Laravel Nova already installed. Let's dive right in!

Note: This tutorial is based on Laravel 10 and Nova 4.

Introduction

In this tutorial, we will learn how to customize the 404 error page in Laravel Nova. By default, Laravel Nova includes a 404 error page component, but if we want to customize it, there isn't a straightforward way to do so. Follow these steps to override Nova's default 404 error page with your own custom page.

Step 1

We will use a Laravel Nova command to create a resource tool that will allow us to override the component. The resource tool must be named in the following format:vendor/custom-nova-components, wherevendor is required, and you can choose any name after the/.

Run the following command:

php artisan nova:resource-tool vendor/custom-nova-components
Enter fullscreen modeExit fullscreen mode

Laravel will prompt you with a few questions, and you should answer "yes" to all of them.

After installing the resource tool, you will see a new directory callednova-components where you will find your custom resource tool, in my casecustom-nova-components.

Image description

Step 2

Now, we will override theCustomError404 component, which is the default view used by Laravel Nova for 404 errors. You can find the original component in:

vendor/laravel/nova/resources/js/views/CustomError404.vue

In our resource tool, locate the tool.js andTool.vue files. RenameTool.vue toCustomError404.vue. Next, register the component intool.js as follows:

import CustomError404 from './components/CustomError404.vue'Nova.booting((app, store) => {  app.component('CustomError404', CustomError404)})
Enter fullscreen modeExit fullscreen mode

As you can see, we've used the same name,CustomError404, as in the Nova package. This will override the default Nova component with our custom one.

Step 3

Once the component is registered, you can customize yourCustomError404.vue as you like. After making your changes, run in directorynova-components/custom-nova-components the following command to compile the changes:

npm run prod
Enter fullscreen modeExit fullscreen mode

That's it! You've successfully overridden the default Nova 404 error page.

Tips and notes

  • Before overriding any Nova component, make sure to locate the component you want to customize in vendor/laravel/nova.
  • You can use the same resource tool to override multiple components. Simply create additional Vue files in the components directory and register them in tool.js using the corresponding component name.
  • Note that overridden components will inherit the default Nova layout, which cannot be changed.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Web and mobile developer, always in search of knowledge
  • Education
    Guatemala
  • Work
    Developer
  • Joined

More fromJenry Mazariegos

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp