I couldn’t work out how to achieve this. I’m probably missing something simple. My current code is this:
$players = Player::find()
->with('team')
->orderBy('first_name', 'team.name')
->all();
// Player drop down
$playerMap = ArrayHelper::map($players, 'player_id', function ($players, $defaultValue) {
return $players->getFullName();
}, 'team.name');
I am trying to generate a dropdown menu that has headings, it currently “works” but the teams are not in alphabetical order. When I tried to just order with ‘team.name’, it errord saying so no such column. So I must be doing it wrong, I did read the docs but couldn’t find this specific example, I may have missed it though.