繁体   English   中英

Laravel Nova 如何使用基于其他 Nova 资源的选项创建选择

[英]Laravel Nova How to create a select with options based on other Nova Resouce

是否可以从其他 Nova 资源创建 Select 选项?

我试图这样做:

Select::make('Contactperson')
     ->rules('required')
     ->options(// Here I want the values from the "Employees"-resource )
     ->displayUsingLabels()
     ->sortable()

我查看了文档并没有找到任何关于此的信息,也许有办法解决?

为此,最好接近 BelongsTo 字段:

https://nova.laravel.com/docs/2.0/resources/relationships.html#belongsto

use Laravel\Nova\Fields\BelongsTo;

BelongsTo::make('Contactperson', 'your_relation_method', 'App\Models\Employees')
    ->rules('required')
->sortable();

试试这样 ->options(\\App\\Models\\Employees::all()->pluck('name', 'id'))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM