[英]Laravel Nova - Can a field dependsOn parent resource field with-in a HasOne relationship
The parent resource has these fields父资源具有这些字段
Select::make('Currency')->options(...),
HasOne::make('Child', 'child', 'App\Nova\ChildResource')->required(),
as I've added HasOne->required, the child resource field are displayed inline (on the same page) while I create (Add new) parent resource.当我添加 HasOne->required 时,子资源字段在我创建(添加新的)父资源时内联显示(在同一页面上)。 The child fields are as follows:
子字段如下:
Text::make('Some Field')
->dependsOn(['???'], function() {}) //it depends upon Currency Field in the parent resource
I want to know if this is possible?我想知道这是否可能? if yes then what attribute I should mention instead of???
如果是,那么我应该提到什么属性而不是??? in dependsOn?
在取决于?
I've tried using 'currency', but it does not work...我试过使用“货币”,但它不起作用......
The other end of the HasOne relationship is a Child's parent function that returns a belongsTo. HasOne 关系的另一端是返回 belongsTo 的 Child 的父级 function。
function parent()
{
return $this->belongsTo(Parent::class);
}
add the relationship in nova在 nova 中添加关系
BelongsTo::make('Parent'),
and then you can use depends然后你可以使用 depends
Text::make('Some Field')->dependsOn(['parent'],
function (Text $field, NovaRequest $request, FormData $formData) {
$model = $request->findModel();
if ($model && $model->parent && $model->parent->currency === 'USD')
{
$field->readonly(true);
}
}
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.