将查询转换为雄辩的orm laravel

时间:2017-03-10 20:06:56

标签: mysql laravel orm

我想转换此查询

select sum(TIME_TO_SEC(`duration`)) from `table`

对Laravel 5的Eloquent ORM

2 个答案:

答案 0 :(得分:0)

我不确定在什么情况下,但如果我找到你,你想要

select sum(TIME_TO_SEC(`duration`)) from `table`

DB::table('table')
->select(DB::raw('sum(TIME_TO_SEC(`duration`))')
->get();

答案 1 :(得分:0)

它适用于我:

Table::selectRaw('sum( TIME_TO_SEC(`duration`) ) as duration')->first();