Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dgoetz's avatar

How do I use Nova components in a custom tool or card?

I'm currently working on a Laravel Nova application in which I need to add a lot of custom tools and cards. I'd like to keep consistency across the whole application, so it makes sense to simply use the existing Laravel Nova components for certain things like form inputs.

I am trying to use a couple of different components found in the nova/resources/js/fields.js file, but it is not working.

In my code, I am simply referencing the <form-date-time></form-date-time> component, but I am receiving errors:

Cannot read property 'attribute' of undefined
Cannot read property 'value' of undefined

I am not a Vue expert, so I'd imagine there is something pretty clear and obvious I am missing. In another SO post, someone referenced doing the same thing I am trying to do with the Nova checkbox component. In that case, there was a prop that needed to be passed to the component in order for it to function correctly, but I don't see a prop that I need to pass to the component at nova/resources/js/components/Form/DateTimeField.vue.

Any help in using Nova components in my custom tools and cards would be appreciated. Thank you.

0 likes
14 replies
bugsysha's avatar
// Tool.vue

<template>
    <div>
        <form-date-time></form-date-time>
    </div>
</template>

<script>
    import FormDateTime from './FormDateTime'

    export default {
        components: {
            FormDateTime,
        },
    }
</script>
dgoetz's avatar

Aren't Nova components available globally? But also, when trying this and trying to import via the absolute path of the component, I get an error when running npm run watch .

This relative module was not found

bugsysha's avatar

Aren't Nova components available globally?

Never tried, but I do not care about that much since I prefer to be explicit.

But also, when trying this and trying to import via the absolute path of the component, I get an error

This is not absolute path, it is relative. Have you provided correct path?

dgoetz's avatar

I tried this path, the relative you provided, and an absolute path. Neither worked.

I'm not necessarily sure this is a Nova issue anymore though, it looks like it might be babel related. When I give the absolute path I get an error related to babel-loader

bugsysha's avatar

So your component is named FormDateTime.vue? And it is in the same folder as Tool.vue?

dgoetz's avatar

No, DateTimeField is a Nova component located at nova/resources/js/components/Form/DateTimeField.vue.

In nova/resources/js/fields.js, the component is registered like Vue.component('form-date-time', required('./components/Form/DateTimeField.vue'))

I think the issue has to do with a difference in laravel-mix versions between my application and nova. Nova is running "laravel-mix": "^1.0" and my app is running "laravel-mix": "^4.0.15".

Because my app is running this version, it requires a different version of babel packages than nova does, and I think what is why babel-loader is part of the stack trace error.

In order to even create custom nova cards and tools, I have to include a .babelrc file in the main directory of each of my custom components that doesn't reference a preset with a version of > 7 like my app .babelrc does. But now, it seems this is a similar issue when trying to use Nova components in my custom components.

I've now tried upgrading the laravel-mix version for each of my custom components (by convention they are the same as nova), and while running npm commands I don't get errors, my components don't render at all.

bugsysha's avatar

Then cd to nova-components/xxxx and run npm run dev/prod.

bugsysha's avatar

You can run npm install within that nova-components/xxx folder also.

dgoetz's avatar

I did both of those. I installed a newer version of laravel-mix but have reverted it now back to the way it was.

I think part of my issue may be trying to use a form component outside of a form-panel component. But, I still haven't quite figured that out either. I think the components registered inside of fields.js are only available inside of a form panel. The components registered in components.js seem to be available everywhere.

I wish there was some documentation regarding re-using nova components. I know all of the source code is available, but it's a little tough to dig through especially as someone who is not proficient with vue.

bugsysha's avatar

Look through Nova Mastery course here on Laracasts and see if there is something that might give you an idea how to resolve it. Hard to figure out with limited info you've provided why it is failing.

dgoetz's avatar

I have looked through that a couple of times - nothing I recall on this subject.

I have changed my approach a bit. I'm now utilizing the <form-panel> component inside of my custom component. I inspected and took the props of a working <form-panel> in nova (as opposed to in my custom tool) and am passing them through to the component in my custom component. This kind of works as I can now render a form with working components, but there are still a few errors, and I'm still really not sure the correct way to pass the props to the <form-panel> component.

Invalid default value for prop "fields": Props with type Object/Array must use a factory function to return the default value.

This is one of the errors I am getting.

webinarincadmin's avatar

nova should add documentation on how to use this nova component, especially when using it in a tool or resource tool.

4 likes
DavidPetrov's avatar

@dgoetz Have you been able to make any progress ever since? I'm also relatively surprised that there's not much documentet on component re-using, since that would be a really powerfull feature. For my case, I'm simply trying to customize one resource creation page, but would, just like you, like to keep the frontend consistent throughout the whole app.

dgoetz's avatar

Hey @davidpetrov - I think I eventually got it working to some degree. I think it was mostly the project that I was working on that resulted in issues. I haven't tried this on a newer project, but I would think it should be as straightforward as it seems.

If I get a chance at some point to try it on a newer project I will document it.

2 likes

Please or to participate in this conversation.