Добрый день, коллеги! Кто может помочь в создании запроса в ORM?
У меня есть чистый sql запрос
select players.*,
count(case when type = 'Goal' then 1 end),
count(case when type = 'Yellow сard' then 1 end),
count(case when type = 'Red card' then 1 end)
from `players`
inner join `events` on `players`.`id` = `events`.`player_id`
where `team_id` in (9, 10)
and `players`.`deleted_at` is null
group by `players`.`id`
, и нет работающего orm
$data = Player::query()
->join('events', function ($join) use ($a, $b){
$join->on('players.id', '=', 'events.player_id')
->whereIn('players.team_id', [$a, $b])
->where('players.deleted_at', '=', null)
->select('players.*',
DB::raw('case when type = "Goal" then 1 end'),
DB::raw('case when type = "Yellow card" then 1 end'),
DB::raw('case when type = "Red card" then 1 end'), 'as count(*) players.id')
->groupBy('players.id');
})
->get();