How can I return the whole item data, I've used max to get the hieghest value but it only returns the value of the field not the whole item
public static function getTeamLeaders($competitionId, $teamId) {
if($teamId){
$ppg = self::where('competitionId', $competitionId)
->where('teamId', $teamId)
->get()
->max('Points');
$apg = self::where('competitionId', $competitionId)
->where('teamId', $teamId)
->get()
->max('Assists');
$fgpg = self::where('competitionId', $competitionId)
->where('teamId', $teamId)
->get()
->max('FieldGoals');
$data = ['ppg' => $ppg, 'apg' => $apg, 'fgpg' => $fgpg];
return $data;
}
}
Result:
array:3 [▼
"ppg" => 15.18
"apg" => 3.76
"fgpg" => 12.04
]
You can use orderBy to sort on the field that you want the max of, and then select the first result.
docs: https://laravel.com/docs/5.4/queries#ordering-grouping-limit-and-offset https://laravel.com/docs/5.4/queries#retrieving-results
$ppg = self::where('competitionId', $competitionId)
->where('teamId', $teamId)
->orderBy('Points', 'desc')
->first();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With