【发布时间】:2022-01-25 13:52:17
【问题描述】:
我所做的这个查询是获取service_id 及其在ServiceOrder 模型中的计数:
$test = DB::table('serviceorders')
->select('serviceorders.service_id', DB::raw('COUNT(services.id) AS count'))
->join('services', 'serviceorders.service_id', '=', 'services.id')
->groupBy('serviceorders.service_id')
->whereMonth('serviceorders.created_at',Carbon::now("Asia/Kuala_Lumpur")->month)
->get();
我不知道如何获取 id 的名称,因为它位于另一个模型中
这是我dd($test)时的结果
如您所见,它显示 service_id 因为是的,我输入了,但我不知道如何获取 serviceName 。如果我尝试使用 chartJs 在饼图中显示它,这种查询方式也可能很困难(如果容易,请纠正我)
这些是涉及的表格
我也在寻找正确的方法来做到这一点。
【问题讨论】: