Level 4
solved
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to group staffs by months and departments. and also calculate the number of records in present column.
My Data table
CREATE TABLE attendance (
id INTEGER NOT NULL
PRIMARY KEY AUTOINCREMENT,
date DATE,
name VARCHAR,
department VARCHAR,
present VARCHAR,
absent VARCHAR,
created_at DATETIME,
updated_at DATETIME,
staff_id VARCHAR
);
My controller
$date = DB::table('attendance')->select('date')->get();
$attendance = DB::table('attendance')
->select('department', DB::raw('DATE_FORMAT(date, "%Y-%b") as `month`'), 'name', DB::raw('SUM(present) AS days_present'))
->groupBy('department', DB::raw('MONTH(date)'))
->get();
What do i do?
solved
Please or to participate in this conversation.