It may sound as a duplicate question. Please I have not found a working solution.I want to add additional field to my query in laravel but I am getting error. This is the php implementation
select id, "extra_column as type" from cases
have tried
DB::table('cases')
->select(['id'])
->selectSub(function($query){
$query->selectRaw('extra_column');
},'type')
->get();
but I keep getting error
4
Answers
I later found out the solution. the extra_column was missing a double quote
You need to use like this:
Please try
addSelect('extra_column as type')
.You can find that scenario in Laravel docs like so,
OR you can do something like this also:
and in case this triggers an issue as you told, please make sure that this column exists in your database.