do you mean this;
$query = DB::table('gpstrackers')
->select('gpstrackers.*', 'users.name')
->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->whereIn('gpstrackers.id', function ($query) use ($from1, $to1, $golfID, $courceid) {
$query->selectRaw('MAX(gpstrackers.id) as id')
->from('gpstrackers')
// ->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->Join('startlists_participants', 'gpstrackers.startliste_participant_ref_id', '=', 'startlists_participants.id')
->Join('startlists', 'startlists_participants.startlist_id', '=', 'startlists.id')
->whereBetween('gpstrackers.regdate', [$from1, $to1])
->where('gpstrackers.golfclub_id', $golfID)
->when($courceid != -99, function $q) {
$q->where('gpstrackers.courcegolfclub_id', $courceid)
}
->groupBy('gpstrackers.flight','gpstrackers.startliste_participant_ref_id');
});
By the way, golf course
and for compatibility between windows and linux, its join not Join