我试图将查询转换为雄辩或找到一种方法在laravel控制器中使用它。
查询是:
select employee, workdate, sum(actualhours)
from ts_data group by employee, workdate;"
使用雄辩模型:
$records = TsData::select(
'employee',
'workdate',
\DB::raw('sum(actualhours) as sumhours')
)
->groupBy('employee', 'workdate')
->get();
或使用DB Facade:
$records = \DB::table('ts_data')->select(
'employee',
'workdate',
\DB::raw('sum(actualhours) as sumhours')
)
->groupBy('employee', 'workdate')
->get();