Here is the query I am using to get results of a camp:
$camp = Camp::where('camps.id', $camp_id)
->with(['athletes' => function ($q) use ($camp_id) {
$q->with(['kickoffs' => function ($q) use ($camp_id) {
$q->where('camp_id', $camp_id);
$q->orderBy('id', 'desc');
}]);
$q->with(['kickoff_results' => function ($q) use ($camp_id) {
$q->where('camp_id', $camp_id);
$q->orderBy('score', 'desc');
}]);
But the results are not getting ordered correctly. I have learned that I must join the tables so now my query looks like this:
$camp = Camp::where('camps.id', $camp_id)
->with(['athletes' => function ($q) use ($camp_id) {
$q->with(['kickoffs' => function ($q) use ($camp_id) {
$q->where('camp_id', $camp_id);
$q->orderBy('id', 'desc');
}])->join('kickoff_results', 'athletes.id', '=', 'kickoff_results.athlete_id')
->orderBy('kickoff_results.score', 'desc');
But this seems to be returning me the same thing. I feel like my results are more accurate with my first query, but the ordering is incorrect.
Any suggestions are greatly appreciated!