class Photo extends Eloquent {
protected $touches = ['city'];
public function city() {
return $this->morphTo() // add this function if not already done
}
}
class City extends Eloquent {
public function photos() {
return $this->morphMany(App\Photo::class, 'city');
}
}
在这种情况下,当照片更新时,它会触及他的父母(在那种情况下的城市) .
希望能帮助到你 .
0
要更新父级的时间戳:
在Photo.php模型中,您可以声明以下行:
class Photo extends Model
{
protected $touches = ['city']; //The 'city' refers to your parent's model
}
2 回答
对于多态关系
在这种情况下,当照片更新时,它会触及他的父母(在那种情况下的城市) .
希望能帮助到你 .
要更新父级的时间戳:
在Photo.php模型中,您可以声明以下行:
现在,当您更新照片模型时,就像您所做的那样:
它将自动更新父级模型的时间戳,在您的情况下,城市表 .