【发布时间】:2018-09-04 04:28:18
【问题描述】:
我有一个user 表,其中包含名称、状态和距离。我想获取特定distance 下的用户,如果结果为空,我想用递增的值再次检查它。
$user = User::where('status',1);
$i = 10;
while($i < 50)
{
$user->having('distance', '<=', $i);
if($user->get()->count())
break;
$i = $i+5;
};
在第一个循环中,我得到了正确的查询SELECT * from users where status = 1 and having distance <= 10。如果在第二个循环中结果为空,我将查询为SELECT * from users where status = 1 and having distance <= 10 and having distance <= 15。我想得到SELECT * from users where status = 1 and having distance <= 15的查询。我应该为此做些什么改变?
【问题讨论】:
标签: sql laravel laravel-5 eloquent laravel-5.6