需求:两个数据库中有两个不相关的表,我需要将它们合并,并在order2中新增不存在的product_name字段,并赋予默认值
$product_name = '默认值';
$news = DB::table("guild_pay.order1")
->where('status', '=', 1)
->selectRaw('product_name','order_no','money','create_time');
$res = Db::table('guild_pay.order2')
->where('status', '=', 1)
->union($news)
->selectRaw('IFNULL(null, ?) as product_name, order_no, money, create_time', [$product_name])
->orderBy('create_time', 'desc')
->paginate(10)->toArray();
ps:记得两个表的字段要一一对应,不可以一边多一边少,也不可以换位置



