How can I do this query with Laravel Eluquent Query Builder

时间:2018-02-03 10:30:33

标签: php mysql sql laravel

if I have

SELECT * FROM slab WHERE 500 >= min_rate and 500 <= max_rate

How can I run this query in Laravel Eloquent way.

3 个答案:

答案 0 :(得分:3)

Eloquent:

Slab::where('min_rate', '<=', 500)->where('max_rate', '>=', 500)->get();

Query Builder:

DB::table('slab')->where('min_rate', '<=', 500)->where('max_rate', '>=', 500)->get();

答案 1 :(得分:0)

已经回答了!

但你也可以考虑一下:

Slab::where([ ['min_rate','>=',500], ['max_rate','<=',500] ])->get()

不需要链接多个,你只需使用一系列条件即可完成。

答案 2 :(得分:0)

您可以直接使用eloquent-query-builder,如下所示:

Slab::whereBetween('min_rate',['mix_range_value','max_range_value])->get();