commentRepo = $commentRepo; parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $connection = \DB::getDefaultConnection(); if ($this->option('database') !== null) { \DB::setDefaultConnection($this->option('database')); } Comment::query()->chunk(100, function ($comments) { foreach ($comments as $comment) { $comment->html = $this->commentRepo->commentToHtml($comment->text); $comment->save(); } }); \DB::setDefaultConnection($connection); $this->comment('Comment HTML content has been regenerated'); } }