From a9c8a7bda525439bf8faa50bd6d41053f0f89ba4 Mon Sep 17 00:00:00 2001 From: Russ Long Date: Sun, 1 May 2022 09:42:47 -0400 Subject: [PATCH] try to fix winner tabulation --- app/Console/Commands/TabulateWinners.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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() ] );