如何在查询中执行“或”“加入”? 帮帮我,谢谢你
$datas = DB::table("stocks")
->where('stocks.code','LIKE',"%{$search}%")
->orWhere('stocks.name', 'LIKE',"%{$search}%")
->join('stocksUnits', 'stocksUnits.code', '=', 'stocks.unit') <--- OR WHERE
->get();
答案 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();