Laravel Eloquent如何在运营商之间使用

时间:2023-01-22 18:56:55

I am trying to find an elegant way in Eloquent and Laravel to say

我想在Eloquent和Laravel找到一个优雅的方式来说

select * from UserTable where Age between X and Y

Is there a between operator in Eloquent (I can't find it).

在Eloquent中有一个介于操作员之间(我找不到它)。

The closest i have gotten so far is chainging my query like this

我到目前为止最接近的是像这样追查我的查询

$query->where(age, '>=', $ageFrom)
      ->where(age, '<=', $ageTo);

I also came across whereRaw that seems to work

我也遇到过似乎有效的R.Raw

$query->whereRaw('age BETWEEN ' . $ageFrom . ' AND ' . $ageTo . '');

Is there an actual Eloquent way (not raw) that deals with ranges?

是否存在处理范围的实际雄辩方式(非原始方式)?

1 个解决方案

#1


28  

$query->whereBetween('age', [$ageFrom, $ageTo]);

Look here: http://laravel.com/docs/4.2/queries#selects

请看这里:http://laravel.com/docs/4.2/queries#selects

#1


28  

$query->whereBetween('age', [$ageFrom, $ageTo]);

Look here: http://laravel.com/docs/4.2/queries#selects

请看这里:http://laravel.com/docs/4.2/queries#selects