简体   繁体   中英

How can I do this query with Laravel Eluquent Query Builder

if I have

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

How can I run this query in Laravel Eloquent way.

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();

Already answered!

But can you also consider this:

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

No need to chain multiple wheres, you can just use an array of conditions and you are done.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM