I'm using the laravel-scout-tntsearch-driver package for Laravel Scout. I have implemented it, and everything works fine. But now I want to do a relational search. I have cities that have many companies.
City.php
public function companies()
{
return $this->hasMany(Company::class);
}
Company.php
public function city()
{
return $this->belongsTo(City::class);
}
public function toSearchableArray()
{
return [
'id' => $this->id,
'title' => $this->title
];
}
Now the search is working only for all companies.
Company::search('bugs bunny')->get();
Also where clauses don't work here. I want something like this:
Route::get('/search/{city}', function (\App\City $city) {
$companies = $city->companies()->search('bugs bunny');
});
I think you got the idea. Thanks!