app/Console/Commands/SyncArticleReplyCount.php
/**
     * Execute the console command.
     *
     * @return mixed
     */
Execute the console command.
@return mixed
Execute the console command . @return mixed
public function handle()
    {
        $this->info('开始同步...');
        $articles = Article::all();
        foreach ($articles as $article) {
            $reply_count = $article->replies()
                                    ->where('visible', true)
                                    ->where('is_deleted', false)
                                    ->count();
            $view_count = $reply_count + random_int(1, 99999);
            $article->update([
                'reply_count' => $reply_count,
                'view_count' => $view_count,
            ]); 
        }
        $this->info('同步生成！');
    }
public function handle ( ) { $ this -> info ( '开始同步...'); $ articles = Article :: all ( ) ; foreach ( $ articles as $ article ) { $ reply_count = $ article -> replies ( ) -> where ( 'visible' , true ) -> where ( 'is_deleted' , false ) -> count ( ) ; $ view_count = $ reply_count + random_int ( 1 , 99999 ) ; $ article -> update ( [ 'reply_count' => $ reply_count , 'view_count' => $ view_count , ] ) ; } $ this -> info ( '同步生成！'); }
Execute the console command.
Execute the console command .
// 在命令行打印一行信息