我为Nova创建了一个自定义字段。在这个领域,我需要获得一些额外的模型数据,如$model->country
,以显示在表单上。如何将此数据传递给Vue组件?
我尝试使用:
return $this->withMeta
但我不知道如何从模型中传递数据。
将自定义字段(如普通字段)添加到资源fields()
,并使用模型中的数据链接自定义方法:
CountryField::make('Country')->country('Germany'),
在Nova组件中定义此自定义方法(请参阅src
文件夹):
public function country($value)
{
return $this->withMeta([
'country' => $value,
]);
}
您可以在FormField.vue
中访问此方法返回的数据,如下所示:
{{ field.country }}