为何重构的代码要放在 Topic.php 中,而不是直接在 ReplyObserver.php 中?
重构的代码放在 Models/topic.php 中,而不是直接重构在Observers/ReplyObserver.php
public function updateReplyCount()
{
$this->reply_count = $this->replies->count();
$this->save();
}
推荐文章: