I have one table where i need to fetch all records along with one custom field too i.e
SELECT
name,
code_no,
'0001' as batch_id // this is cutome field
FROM
mytable //batch_id is cutom filed
i tried
MyTable::select('name','code_no','00101 as batch_id')->get();
Any ideas please??
You can do it this way:
MyTable::select('*', DB::raw('"0001" as `batch_id`'))->get();
It will select all columns form your model table as well as 0001 as batch_id. DB::raw makes sure the param is applied "as is" without trying to "convert" 0001 into column name.