laravel - Laravel:在多个 Where Claus 中使用 OR
问题描述
将 SQL 转换为 Laravel 格式对我来说仍然有点混乱。我需要使用 OR。如果 onloan = NULL OR 0 则显示记录。
下面的代码只能检测 0 而不能检测 NULL。
public function finditembarcode () {
if ($finditembarcode = \Request::get('q')) {
$itembarcode = Item::where(Item::raw("BINARY `itembarcode`"), $finditembarcode)
->where('onloan','=', NULL OR 0)
->paginate();
}else{
$itembarcode = ''; //If nothing found, don't return anything.
}
return $itembarcode;
}
我也尝试过,但得到的结果与上面的代码相同。
->where('onloan','=', NULL || 0)
解决方案
Laravel数据库查询生成器 whereNull / whereNotNull / orWhereNull / orWhereNotNull
->where('onloan', 0)->orWhereNull('onloan')
推荐阅读
- google-apps-script - 如何将 Google Doc 保存为 PDF?
- javascript - 在某些页面中重复调用 API 端点以调度 Vuex 操作
- c++ - 如何将变量直接传递给编译器并在代码 CMake 中访问它们?
- scala - Scala Spark 在数据帧和数据集中以不同方式处理 Double.NaN
- google-analytics - Google Analytics 管理 API v3 服务不可用
- google-apps-script - 在 GAS 中的所有脚本(包括容器绑定文件)中搜索字符串
- google-app-engine - 无法从 Google App Engine 下载静态文件
- gradle - 如何解决 Gradle 中的“无法设置类型对象的只读属性 'classpath' 的值 ...”错误
- javascript - 获取 Cognito 身份验证事件以在 UI 中显示?
- jmeter - loadrunner的truclient协议中如何调用外部API