首页 > 解决方案 > 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

解决方案


Laravel数据库查询生成器 whereNull / whereNotNull / orWhereNull / orWhereNotNull

->where('onloan', 0)->orWhereNull('onloan')

推荐阅读