看视频发现是不是少了两步
- 因为在
Reply.php
里已经定义了protected $with = ['owner', 'favorites'];
以及
Favoritable.php
当中定义了public function getFavoritesCountAttribute() { return $this->favorites->count(); }
所以在
Thread.php
当中对关联关系replies进行修改public function replies() { return $this->hasMany(Reply::class); }
- 因为在
Thread.php
定义了protected $with = ['creator', 'channel'];
所以
ThreadController.php
里对getThreads
方法去掉with$threads = Thread::latest()->filter($filters);
推荐文章: