Reputation: 55
I am trying to convert a query to eloquent or find a way to use it in a laravel controller.
The query is:
select employee, workdate, sum(actualhours)
from ts_data group by employee, workdate;"
Upvotes: 1
Views: 1082
Reputation: 9055
Using Eloquent Model :
$records = TsData::select(
'employee',
'workdate',
\DB::raw('sum(actualhours) as sumhours')
)
->groupBy('employee', 'workdate')
->get();
or using DB Facade :
$records = \DB::table('ts_data')->select(
'employee',
'workdate',
\DB::raw('sum(actualhours) as sumhours')
)
->groupBy('employee', 'workdate')
->get();
Upvotes: 2