Laravel eloquent using null as column value on select?

Clash Royale CLAN TAG#URR8PPP
Laravel eloquent using null as column value on select?
How to use null as column value in the Laravel eloquent like in the following query (The below query is not working and its for an example).
$query = DB::table('invoices as inv')
->leftjoin('customer as c', 'c.id', '=', 'inv.customer_id')
->select([
'inv.id',
'inv.invoice_date',
'inv.invoice_no',
'null as voucher_no',
'null as credit',
]);
Here, 'null as voucher_no' is not working. How to use null inside this query.
1 Answer
1
Use DB::raw around your columns, which will force laravel to pass the column name as is:
DB::raw
$query = DB::table('invoices as inv')
->leftjoin('customer as c', 'c.id', '=', 'inv.customer_id')
->select([
'inv.id',
'inv.invoice_date',
'inv.invoice_no',
DB::raw('null as voucher_no'),
DB::raw('null as credit'),
]);
@FrankerZ Thank you for pointing me. I have marked answers for my question.
– Jinto Antony
Aug 12 at 6:03
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
@JintoAntony You can mark it as answer! Answerer can't.
– Smartpal
Aug 12 at 5:32