teamtnt / laravel-scout-tntsearch-driver

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch
MIT License
1.1k stars 144 forks source link

Problem with $touches and toSearchableArray #232

Closed AugustBurnsRed closed 3 months ago

AugustBurnsRed commented 5 years ago

Hi, i have two models, School and Service.

In school

protected $touches = ['services'];

public function services()
{
  return $this->belongsToMany(Service::class);
}

and in service

public function schools()
{
  return $this->belongsToMany(School::class);
}

public function toSearchableArray()
{
      $array = $this->toArray();
      $array['schools'] = $this->schools()->pluck('name')->implode(' ');

      return $array;
}

When i update a school name i want it to be updated in the services index. The updated_at in my main BD is updated but toSearchableArray() is not triggered.

If i remove the protected $touches and replace it with this in my update function it's working fine

foreach ($school->services as $service) {
   $service->touch();
}

I don't see why it's not working with $touches and i would prefer to just use that instead of touch(). I think that it was working when i was using Algolia but i'm not sure.

Thanks!