我正在尝试UNION两个查询。这是我的代码:
public function ledger()
{
$name = Input::get('client');
$invoices = DB::table('invoices')
->where('client',$name)
->selectRaw('`invoiceNumber` as `voucher`,`date`,(`bill` + `ot_bill`) as `amount`');
$cashIns = DB::table('cash_ins')
->where('client',$name)
->select('voucher','date','amount')
->unionAll($invoices)
->get();
return view('cashIn.ledger',compact('cashIns'));
}
但是日期没有显示在表格中。当我查看dd($cashIns)
时,所有日期都被破坏或格式不同。我不明白到底有什么回报。
array:3 [▼
0 => {#301 ▼
+"voucher": "JKL02390"
+"date": b"ß\x07\f\x06" //it suppose to be 2015-12-06
+"amount": 23888
}
1 => {#304 ▼
+"voucher": "KL8430" //it suppose to be 2015-10-07
+"date": b"""
ß\x07\n
\x07
"""
+"amount": 98392
}
2 => {#305 ▼
+"voucher": "433"
+"date": b"ß\x07\f\x02" //it suppose to be 2015-12-02
+"amount": 9849
}
]
当我单独dd('invoices')
和dd('cashIns')
没有UNION时,所有日期都格式正确并且完全显示为数据库。