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

WebKenth's avatar

Retrieving Resource from custom field

I have a form field where i want to use information on the current Resource however the form field is only passed 'resourceName', 'resourceId', 'field' in its props. Missing the resource

When looking at components like nova/resources/js/components/Detail/TextField.vue i can see it expects a resource prop.

Anyone know how to retrieve the resource?

I could "just" make an API call to fetch the resource since i have the id, however it is already loaded and would seem like a dirty hack.

0 likes
2 replies
WebKenth's avatar
WebKenth
OP
Best Answer
Level 16

Ok so this is a REALLY hacky solution You can resolve the fields value and pass it a json array of the model like so:

YourNovaFieldHere::make('Name')->resolveUsing(function () {
    return json_encode($this->toArray());
}),

And then in your FormField.vue file you can on created() parse it and now you have access to the model data

1 like
TimothePearce's avatar

You can also use the "resource" prop on your TextField component. Then inside you can access the id with this.resource.id.value

Please or to participate in this conversation.