Php SQL查询到laravel查询生成器-转换
如何将此查询转换为Laravel查询生成Php SQL查询到laravel查询生成器-转换,php,sql,laravel,Php,Sql,Laravel,如何将此查询转换为Laravel查询生成 SELECT stocks.* FROM stocks, stocksUnits WHERE stocks.name LIKE '%eg%' OR (stocksUnits.code = stocks.unit and stocksUnits.comment LIKE '%eg%') 例如: $datas = Stocks::where('code','LIKE',"%{$search}%") 请看这个 $stocks
SELECT stocks.* FROM stocks, stocksUnits WHERE stocks.name LIKE '%eg%' OR (stocksUnits.code = stocks.unit and stocksUnits.comment LIKE '%eg%')
例如:
$datas = Stocks::where('code','LIKE',"%{$search}%")
请看这个
$stocks = DB::table(DB::raw('stocks as stock', 'stockUnits as stockUnit'))
->select('stock.*')
->where('stock.name','LIKE',"%eg%")
->orWhere(function($query)
{
$query->where('stockUnits.code','=','stock.unit')
->where('stockUnits.comment','like','%eg%');
}
)
谢谢。SQLSTATE[42S22]:找不到列:1054 where子句中的未知列'stockUnit.code'