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.
Hi, i have two models, School and Service.
In school
and in service
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
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!