![](/img/trans.png)
[英]Issue displaying Metrics Trend with Laravel Nova - Too few arguments
[英]Too few arguments Laravel Nova relatable query with fields
我有一个关系需要根据它用于填充的 Laravel Nova 字段进行不同的过滤。
A single Locations has one or more Locations attached as options
(BelongsToMany)
A single Process_type also has a single Locations set as a default
(BelongsTo)
我正在使用相关查询来过滤这两个字段中每个字段的可用选项。
我的 Location 资源中的字段如下:
BelongsToMany::make('Neighborhood Locations', 'relatedLocations', Location::class)
->searchable()
相关查询如下所示:
public static function relatableLocations(NovaRequest $request, $query, Field $field)
{
if ($field instanceof BelongsToMany) {
return $query->where('location_type_id', '=',8);
}
return $query;
}
此模式来自 Laravel Nova 关于动态相关模型的文档 ( https://nova.laravel.com/docs/3.0/resources/authorization.html#dynamic-relatable-methods )。 它描述了将字段作为第三个参数添加到相关查询中,然后在有条件的情况下使用它来选择过滤器逻辑。
我得到的错误是:
Too few arguments to function AppNovaProcess_type::relatableLocations(),
2 passed and exactly 3 expected
根据文档,我的make()
调用具有三个参数,知道我缺少什么吗?
我在 Laravel 7.x 和 Nova 3.x
来源:Laravel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.