我正在try 用拉威尔联盟来实现一个结果.
[
{
warehouse_id: 12,
warehouse_name: "new",
wi_id: 19,
wi_type: "storage",
wi_name: "1",
wr_id: 20,
wr_name: "1",
wb_id: 3,
wb_name: "1",
wp_id:null,
wp_type:null,
wp_location:null,
},
{
warehouse_id: 12,
warehouse_name: "new",
wi_id: 19,
wi_type: "storage",
wi_name: "1",
wr_id: 20,
wr_name: "1",
wb_id: 6,
wb_name: "2",
wp_id:"1",
wp_type:"fixed",
wp_location:"hellow",
}
]
为了得到解决方案,我使用了两个查询并将它们合并在一起,我希望在一个查询中有结果,但没有运气...
$pickings = Warehouse::where('warehouses.id', $id)
->leftJoin('warehouse_pickings as wp', 'wp.warehouse_id', '=', 'warehouses.id')
->groupBy('wp.id')
->select(
'wp.id as wp_id',
'wp.type as wp_type',
'wp.location as wp_location',
);
$config = Warehouse::leftjoin('warehouse_isles as wi', 'wi.warehouse_id', '=', 'warehouses.id')
->leftjoin('warehouse_racks as wr', 'wr.warehouse_isle_id', '=', 'wi.id')
->leftJoin('warehouse_bins as wb', 'wb.warehouse_rack_id', '=', 'wr.id')
->where('warehouses.id', $id)
->groupBy('wb.id', 'wr.id', 'wi.id')
->select(
'warehouses.id as warehouse_id',
'warehouses.name as warehouse_name',
'wi.id as wi_id',
'wi.type as wi_type',
'wi.name as wi_name',
'wr.id as wr_id',
'wr.name as wr_name',
'wb.id as wb_id',
'wb.name as wb_name',
);
$query = $config->unionAll($pickings);
return $query->paginate(5);
我所犯的错误 SQLSTATE[21000]:违反基数:1222使用的SELECT语句具有不同的列数
任何帮助都将不胜感激.
谢谢