【发布时间】:2019-05-12 10:00:17
【问题描述】:
在 Laravel Nova 中,我有 BelongsToMany 关系(公司 - 支点 - 请求)。
在数据透视表中,我有一些额外的列,我可以使用数据透视字段 (https://nova.laravel.com/docs/1.0/resources/relationships.html#belongstomany) 访问这些列,效果很好。
但现在我有一个特殊情况,我有一个从数据透视表到第三个表(状态)的附加 BelongsTo 关系。我试图在枢轴字段中定义一个 BelongsTo 字段,但这不起作用。
BelongsToMany::make('Companies', 'companies', Company::class)->fields(new CompanyRequestFields()),
透视字段:
class CompanyRequestFields
{
/**
* Get the pivot fields for the relationship.
*
* @return array
*/
public function __invoke()
{
return [
Number::make('preis'),
Text::make('bezahlt'),
BelongsTo::make('State', 'state', States::class),
];
}
}
我得到的错误:
Call to undefined method Illuminate\Database\Eloquent\Relations\Pivot::state()
关系 state() 实际上存在于枢轴模型上,并且还有一个 Nova 资源 State 类。
所以看起来 PivotFields 不支持此功能?或者有谁知道它是否有可能做到这一点?
【问题讨论】:
-
您好,您能找到任何解决方案吗?
标签: laravel-nova