laravel - 如何检查 Laravel 查询中哪个条件有数据
问题描述
type == 'supplier'
如果没有,我希望找回type == 'retailer'
。而我只希望检索type == 'retailer'
,如果两者type
也有客户的话。
有没有办法将以下查询条件组合成一个查询?
$data = Sale::where('type', 'retailer')->where('customer', 'LIKE', '%peter%')->get();
if (count($data) == 0) {
$data = Sale::where('type', 'supplier')->where('customer', 'LIKE', '%peter%')->get();
}
解决方案
推荐阅读
- firebase - 有没有比我现在拥有的更好的方法来编写这个 firebase 云功能?
- vue.js - Vue 样式范围
- c# - 2d 滚动背景效果
- javascript - Map 在 React 中的第一次迭代后停止迭代
- javascript - 从事件中心获取消息到变量
- c++ - Ncurses 和 gdb 屏幕在调试时重叠。所以我想把两个屏幕分开
- java - 使用 Java 文件写入器将文件写入共享驱动器 (NAS) 的权限问题
- ios - 而不是删除一个数组,我希望它将数组发送到另一个 UIViewController
- angular - 在navigateByUrl()时Angular动态路由名称不起作用,需要刷新页面
- laravel - Laravel JWT:无法实现 JWTSubject