我需要在Belongs To Fields中显示所选国家/地区是否有任何方法我可以传递该值,默认情况下会选择它。
从这个关于Github的issue,我在我的一个BelongsTo
关系中尝试了以下内容,
BelongsTo::make('countries')
->withMeta([
'belongsToId' => 1 // default value for the select
]);
..它完美无缺。
您希望确保在编辑时正确设置该值,因此请使用以下代码:
BelongsTo::make('countries')
->withMeta([
'belongsToId' => $this->countries_id ?? 1 // default value for the select
]);