postComment = $postComment; } /** * Execute the console command. * * @return mixed */ public function handle() { $this->line("开始更新评论回复数量"); $bar = $this->output->createProgressBar($this->postComment->where('parent_id', 0)->count()); $this->postComment->where('parent_id', 0)->chunk(100, function($comments) use ($bar){ foreach($comments as $comment){ $replyCount = $this->postComment->where('parent_id', $comment->id)->count(); if($replyCount){ $comment->reply_count = $replyCount; $comment->save(); } $bar->advance(); } usleep(100000); }); $bar->finish(); $this->line("\n更新评论回复数量结束"); } }