如何过滤Laravel Nova选择字段的选项

时间:2019-12-29 13:26:16

标签: laravel laravel-nova

我的资源类型为 Process_type

它与 Process_event

具有BelongsToMany关系

它还将默认的 Process_event 存储为BelongsTo关系-我希望此操作的可能选项仅限于BelongsToMany关系中的那些,而不是数据库中整个过程事件的集合。 / p>

我原本希望能够限制BelongsTo::make()字段上的选项,但找不到解决方法。因此,我回过头来使用“选择”字段,并通过options()方法传递选项。

这是我的字段方法当前的外观

public function fields(Request $request)
{
    $options = [];
    $options['process_events'] = \App\Process_event::all()->pluck('title','id');
    return [
        ID::make()->sortable(),
        Text::make('Title')->sortable(),
        Select::make('Process Event')->options($options['process_events']),
        BelongsToMany::make('Process Events', 'process_events', Process_event::class)
    ];
}

就目前而言,我仍然将所有过程事件作为选项。如何通过传入的$request对象访问当前实体,因此可以在模型上查找->process_events()。我找不到与此有关的任何文档。

这可能吗?如果没有,哪种更好的方法呢?

0 个答案:

没有答案
相关问题