关于BelongsTo的可搜索方法在laravel nova中不起作用,不返回任何物品

问题描述 投票:0回答:1

我有一个名为Customer的模型,该模型具有HasManyNotes]模型的关系

public function notes()
{
    return $this->hasMany(Note::class);
}

Note

Customer具有BelongsTo关系
public function customer()
{
   return $this->belongsTo(Customer::class);
}

然后我在Note

nova resource]中定义了相同的关系>
BelongsTo::make('Customer', 'customer', Customer::class)

直到这里,如果要在BelongsTo字段上调用->searchable(),它不会从搜索中返回任何东西,那么现在所有东西都可以正常工作了>>

BelongsTo::make('Customer', 'customer', Customer::class)->searchable()

我该如何解决这个问题

我有一个名为Customer的模型,具有HasMany关联到Notes模型公共函数notes(){return $ this-> hasMany(Note :: class); }和Note与客户之间具有BelongsTo关系...

您调用srearchable()的字段必须位于资源中的搜索数组中。

因此,如果您的字段是BelogsTo,则必须将您所属资源的title

字段放入sreach数组中

在我的情况下,标题字段为

public static $title = 'name';

所以我把它放在

public static $search = [
    'id',
    'name',
];

一切都会按预期进行

php laravel laravel-nova nova
1个回答
0
投票

您调用srearchable()的字段必须位于资源中的搜索数组中。

© www.soinside.com 2019 - 2024. All rights reserved.