我在Nova中创建了一个自定义Field,我想在视图中显示一个类别列表,并且复选框将与每个类别相关联。
我已经在我的资源文件中有一个类别的递归数组,但我不知道如何将它传递给FormField?
这是我的代码:
类别资源
$resourceId = $request->route()->parameter('resourceId');
$categories = app(self::$model)->where('id', '!=', $resourceId)->orderBy('position', 'ASC')->get()->toTree();
谢谢您的帮助!!!
你可以传递$categories
作为字段选项,请参阅docs https://nova.laravel.com/docs/1.0/customization/fields.html#registering-fields。
CustomField::make('name custom field')->withMeta(['categories' => $categories]);