【发布时间】:2023-04-08 02:16:01
【问题描述】:
例如,这样做:
Model::where('role', 'all')->orWhere('role','user')->first();
总是首先获取角色为“all”的模型,因为 where() 的声明早于 orWhere()?
或者我不应该相信它并总是检查 if 吗?
$foo = new Model;
$bar = $foo->where('role', 'all')->first();
if(empty($bar)){
$bar = $foo->where('role','user')->first();
}
或者也许是更好的解决方案?
【问题讨论】: