laravel - update parent timestamps when updating child model in polymorphic relationship -
in laravel 5.1 have 2 models.a city model , photo model.
there polymorphic relation between city , photo. while updating city's photo with
$city->photos()->updateorcreate($attributes,$values)
the child time stamps updates. parent model's timestamp , city in case, not update accordingly , should manually call
$city->touch()
how can update parent model's timestamp when touching child model in laravel?
for polymorphic relations
class photo extends eloquent { protected $touches = ['city']; public function city() { return $this->morphto() // add function if not done } } class city extends eloquent { public function photos() { return $this->morphmany(app\photo::class, 'city'); } }
in case, when photo updated, touches parent (city in situation).
hope helps.
Comments
Post a Comment