1
votes

I created a custom field for Nova. On this field I need to get some extra model data like $model->country to show on the form. How can I pass this data to the Vue component?

I try to use:

return $this->withMeta

But I don't know how to pass the data from the model.

1

1 Answers

3
votes

Add the custom field like a normal field to the resource fields() and chain a custom method with the data from the model:

CountryField::make('Country')->country('Germany'),

Define this custom method in your Nova component (see src folder):

public function country($value)
{
    return $this->withMeta([
        'country' => $value,
    ]);
}

You can access the returned data from this method in FormField.vue like this:

{{ field.country }}