【发布时间】:2014-04-15 17:23:28
【问题描述】:
在 Laravel 中,我想定义一个祖父母类型的 eloquent 关系,以便在添加或更新时让孙子触摸祖父母(例如,如果它给祖父母带来一张非常漂亮的生日贺卡)。假设我有一个像 Collection > post > comment 这样的层次结构。
--Comment--
protected $touches = array('post', 'collection');
public function post()
{
return $this->belongsTo('Post');
}
public function order()
{
// not working
// return $this->post->collection();
// not working
// return $this->belongsTo('Post')->belongsTo('Collection');
}
--Post--
public function collection()
{
return $this->belongsTo('Collection');
}
我希望在添加评论时运行集合中的更新功能。我该如何设置?
我正在使用 Laravel 4.1
【问题讨论】:
标签: laravel laravel-4 relationship eloquent