Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 如何以雄辩的语言定义一段触动祖父母的关系_Laravel_Laravel 4_Relationship_Eloquent - Fatal编程技术网

Laravel 如何以雄辩的语言定义一段触动祖父母的关系

Laravel 如何以雄辩的语言定义一段触动祖父母的关系,laravel,laravel-4,relationship,eloquent,Laravel,Laravel 4,Relationship,Eloquent,在Laravel中,我想定义一种祖父母类型的雄辩关系,以便在添加或更新时,我可以让孙子孙女触摸祖父母(例如,如果它给祖父母带来一张非常漂亮的生日卡)。假设我有一个像集合>帖子>评论这样的层次结构 --Comment-- protected $touches = array('post', 'collection'); public function post() { return $this->belongsTo('Post'); }

在Laravel中,我想定义一种祖父母类型的雄辩关系,以便在添加或更新时,我可以让孙子孙女触摸祖父母(例如,如果它给祖父母带来一张非常漂亮的生日卡)。假设我有一个像集合>帖子>评论这样的层次结构

--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');
    }
我希望集合中的更新函数在添加注释时运行。我该怎么设置呢

我使用的是Laravel4.1

我希望集合中的更新函数在注释被删除时运行 补充说

我对更新功能有点困惑,但是

您可以为此注册一个事件处理程序,例如,将其添加到您的
Comment
模型中:

class Comment extends Eloquent {

    public static function boot()
    {
        parent::boot();

        static::created(function($comment)
        {
            // $comment is the current Comment instance
        });
    }
}

因此,无论何时创建任何
注释
,事件处理程序(匿名函数)都将运行,以便您可以在该函数中执行某些操作。阅读更多信息。

是的,我的收藏课上有。我计划使用
protected$touchs=…
自动更新集合,以便运行更新。但它似乎不起作用,所以我可能不得不手工操作