Reputation: 468
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.
Upvotes: 2
Views: 6334
Reputation: 22921
Use DB::raw
around your columns, which will force laravel to pass the column name as is:
$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'),
]);
Upvotes: 10