Laravel Eloquent event not triggered when model is touched
Laravel 5.7. I have 2 models: Foo and Content:
class Foo extends Model
{
public static function boot()
{
parent::boot();
static::updated(function() {
dd('here');
});
}
public function contents()
{
return $this->morphToMany('App\Content');
}
}
class Content extends Model
{
protected $touches = ['foos'];
public function foos()
{
return $this->morphedByMany('App\Foo');
}
}
When Content is updated, it correctly touches Foo, updating its updated_at timestamp. But the static::updated method is not called. I would expect it to be called since Foo has been updated.
The idea behind touching the parent is just to update the timestamps. I think the timestamps are exempt from a model that has been considered to have updated values, which is why your boot method doesn't fire.
For whatever scenario you're trying to make this work, It looks like you might need to explicitly call a method on your parent model.