问:如何在Eloquent

时间:2015-12-21 17:47:14

标签: laravel eloquent

如果我有两个字段(比如说field1和field2)

如何在Eloquent中创建此查询?

SELECT * FROM `table` WHERE `field1` < `field2`;

$query->where('field1','<','field2')

不起作用。反引号也不起作用......

2 个答案:

答案 0 :(得分:3)

$query->whereRaw('field1 < field2');

答案 1 :(得分:0)

根据laravel doc

$users = DB::table('users')
                ->where('field1', '<', 'field2')
                ->get();
在Eloquent中

$users = User::where('field1', '<', 'field2')
                    ->get();