簡體   English   中英

太少 arguments Laravel Nova 相關字段查詢

[英]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

relatableLocations 中不應有第四個參數。 因此,從 function 中刪除Field $field

從 Nova 文檔中查看相關過濾以獲取更多信息:

相關過濾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM