我试图在 Eloquent 和 Laravel 中找到一种优雅的方式来表达
I am trying to find an elegant way in Eloquent and Laravel to say
select * from UserTable where Age between X and Y
Eloquent 中是否有 between 运算符(我找不到).
Is there a between operator in Eloquent (I can't find it).
到目前为止我得到的最接近的是像这样链接我的查询
The closest i have gotten so far is chainging my query like this
$query->where(age, '>=', $ageFrom)
->where(age, '<=', $ageTo);
我也遇到过 whereRaw 似乎有效
I also came across whereRaw that seems to work
$query->whereRaw('age BETWEEN ' . $ageFrom . ' AND ' . $ageTo . '');
是否有处理范围的实际 Eloquent 方式(非原始)?
Is there an actual Eloquent way (not raw) that deals with ranges?
$query->whereBetween('age', [$ageFrom, $ageTo]);
看这里:http://laravel.com/docs/4.2/queries#selects一个>
仍然适用于 Laravel 5:https://laravel.com/docs/5.8/queries#where-clauses
Still holds true for Laravel 5: https://laravel.com/docs/5.8/queries#where-clauses
这篇关于Laravel Eloquent 如何在操作符之间使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
PHP、MySQL PDOException 的死锁异常代码?Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL 可滚动游标不起作用PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
PHP PDO ODBC 连接PHP PDO ODBC connection(PHP PDO ODBC 连接)
使用 PDO::FETCH_CLASS 和魔术方法Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo 只从 mysql 获取一个值;等于变量的值php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO 找不到驱动程序MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)