I am trying to get a status count of some processes and tasks just like a to-do list tasks count. My current database look like this SQL Database Structure
+----+---------+------------+-------------+---------+------------+---------------------+---------------------+
| id | user_id | list_id | name | records | status | created_at | updated_at |
+----+---------+------------+-------------+---------+------------+---------------------+---------------------+
| 1 | 1 | 8Kwvf8ikcV | 10 mails | 19 | On-Hold | 2021-03-11 07:56:17 | 2021-03-11 07:56:17 |
| 2 | 1 | a0pJRv4Zfc | temp_emails | 884 | On-Hold | 2021-03-11 08:02:13 | 2021-03-11 08:02:13 |
| 3 | 1 | xrgZZkrLFA | 10 mails | 19 | Processing | 2021-03-11 08:06:37 | 2021-03-11 08:06:37 |
| 4 | 1 | lDOX8p2sgU | 10 mails | 19 | Completed | 2021-03-11 08:53:51 | 2021-03-11 08:53:51 |
+----+---------+------------+-------------+---------+------------+---------------------+---------------------+
I am using
return $listStats = ListName::select([
DB::raw("status"),
DB::raw("COUNT(status) as count")
])->where('user_id', Auth::id())
->groupBy('status')
->get();
Query to get the database and its count.
Current laravel out put is showing as
[{"status":"Completed","count":1},{"status":"On-Hold","count":2},{"status":"Processing","count":1}]
My question is how can I get the count of completed status without using foreach loop?
Do I need to change my query? or can I simply use $listStats['Completed']['count'] ?