我想根据'leave_policy'的名称计算一个字段名'leave_policy',我正在使用连接来完成它。我的数据库是这样的 https://imgur.com/a/gR3Dw
我希望在应用部分显示计数。例如,如果我想分别计算所有“紧急叶子”和“父亲叶子”,我已经应用到现在。 https://imgur.com/a/dvjuX
$join = DB::table('leaves_policy')
->join('leaves_policies', 'leaves_policy.leave_policy', '=', 'leaves_policies.title')
->join('leaves_requests', 'leaves_policy.requested_by' , '=', 'leaves_requests.requested_by')
->select('leaves_policy.*', 'leaves_policies.title', 'leaves_policies.total_no_of_leaves_allowed_per_year',
'leaves_policies.no_of_months_leaves_valid', 'leaves_policies.max_leaves_per_month', 'leaves_policies.max_con_leaves_per_month',
'leaves_requests.leave_status', DB::raw('COUNT(leaves_policy.leave_policy) as count'))
->groupBy('id')
->get();