SELECT
team_name,
(CASE WHEN `assignment` = 'Appeal/Recon/Claim Review' THEN `done` ELSE 0 END) AS 'Appeal',
(CASE WHEN `assignment` = 'IDR' THEN `done` ELSE 0 END) AS 'IDR'
FROM
operation_assignments
WHERE
serial = 6
GROUP BY
team_name
$collections = DB::table('operation_assignments')
->select(
'team_name',
DB::raw("CASE WHEN assignment = 'Appeal/Recon/Claim Review' THEN done ELSE 0 END AS Appeal"),
DB::raw("CASE WHEN assignment = 'IDR' THEN done ELSE 0 END AS IDR")
)
->where('serial', 6)
->groupBy('team_name')
->get();
2
Answers
$collections = OperationAssignment::select(['team_name', DB::raw("SUM(CASE WHEN assignment='Appeal/Recon/Claim Review' THEN done END) as 'appeal'"), DB::raw("SUM(CASE WHEN assignment='IDR' THEN done END) as 'idr'"), ])->where('serial',6)->groupBy('team_name')->get();
You don’t need to do anything. Eloquent extends the base query builder so the syntax is the same. The only difference is instead of
DB::table('operation_assignments')
, you use your model (I’m assuming it’sAppModelsOperationAssignment
).