【发布时间】:2016-07-07 18:35:21
【问题描述】:
我有以下疑问:
$foundItem = ItemDrop::where('zone_id',$this->user->zone_id)
->where('find_rate','>=',$itemChance)
->orderBy('find_rate','desc')
->take(1);
在我的数据库中,如果我希望 ItemDrop 在所有区域中可用,我设置 zone_id = "-1"。
所以我一直在考虑如何将它添加到我的查询中..
$foundItem = ItemDrop::where('zone_id',$this->user->zone_id)
->orWhere('zone_id',"-1")
->where('find_rate','>=',$itemChance)
->orderBy('find_rate','desc')
->take(1);
但感觉不对,可能无法正常工作,因为我有 2 个 Wheres,而 OrWhere 应该只包含在第一个 where 中:where('zone_id',$this->user->zone_id)。
如何使用zone_id -1 AND $this->user->zone_id 获取 ItemDrop 的所有记录?
如果没有 Laravel,我的 DESIRED 查询会是什么样子:
SELECT * FROM ItemDrops WHERE( zone_id = "-1" || zone_id = $this->user->zone_id) && find_rate >= $itemChance
【问题讨论】: