Laravel或在哪里加入

时间:2020-08-19 22:16:54

标签: php laravel

如何在查询中执行“或”“加入”? 帮帮我,谢谢你

$datas =  DB::table("stocks")
          ->where('stocks.code','LIKE',"%{$search}%")
          ->orWhere('stocks.name', 'LIKE',"%{$search}%")
          ->join('stocksUnits', 'stocksUnits.code', '=', 'stocks.unit') <--- OR WHERE
          ->get();

1 个答案:

答案 0 :(得分:2)

$datas =  DB::table("stocks")
          ->where('stocks.code','LIKE',"%{$search}%")
          ->orWhere('stocks.name', 'LIKE',"%{$search}%")
          ->orWhere(static function ($query) {
              $query->join('stocksUnits', 'stocksUnits.code', '=', 'stocks.unit');
          })
          ->get();