diff --git a/app/Console/Commands/TabulateWinners.php b/app/Console/Commands/TabulateWinners.php index 20b3879..f6cf2e1 100644 --- a/app/Console/Commands/TabulateWinners.php +++ b/app/Console/Commands/TabulateWinners.php @@ -58,7 +58,21 @@ class TabulateWinners extends Command ->orderBy('totalscore','desc') ->first(); return $bestInShowWinnerQuery->vehicle; - } + } + + function bestInShow2ndWinner() + { + $bestInShow2ndWinnerQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + ->groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function($query){ + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $bestInShow2ndWinnerQuery->vehicle; + } function pcWinner() { @@ -142,7 +156,7 @@ class TabulateWinners extends Command 'place' => 'second' ], [ - 'vehicle' => bestInShowWinner() + 'vehicle' => bestInShow2ndWinner() ] );