5

我正在为 Laravel Scout 使用laravel-scout-tntsearch-driver包。我已经实现了它,一切正常。但现在我想做一个关系搜索。我有很多公司的城市。

城市.php

public function companies()
{
    return $this->hasMany(Company::class);
}

公司.php

public function city()
{
    return $this->belongsTo(City::class);
}

public function toSearchableArray()
{
    return [
        'id' => $this->id,
        'title' => $this->title
    ];
}

现在搜索只适用于所有公司。

Company::search('bugs bunny')->get();

where 子句在这里也不起作用。我想要这样的东西:

Route::get('/search/{city}', function (\App\City $city) {
    $companies = $city->companies()->search('bugs bunny');
});

我想你明白了。谢谢!

4

0 回答 0