/** * Execute the console command. * * @return void */ public function fire() { DB::connection()->disableQueryLog(); $conn = DB::connection('stats'); $conn->disableQueryLog(); $rows = DailyAction::select(DB::raw('user_id, Sum(points) as points'))->with(['user' => function ($q) { $q->select(['name', 'avatar']); }])->groupBy('user_id')->orderBy('points', 'desc')->get(); foreach ($rows as $row) { $user = User::find($row['user_id']); $user->total_points = $row['points']; $user->save(); } $this->info('All users processed'); }