Laravel 5 SQLSTATE [42S22]: column not found
I am making multiple connections and trying to get data. My query builder:
$datasource = DB::table('vehicles')->join('brands', 'vehicles.brand_id', '=', 'brands.id')->join('sections', 'vehicles.section_id', '=', 'sections.id')->select('vehicles.*, vehicles.id AS vid');
But I am getting this error:
SQLSTATE [42S22]: Column not found: 1054 Unknown column "vehicle.model" in the field list (SQL: select
vehicles
.model,
AsAS
fromvehicles
inner joinbrands
onvehicles
.brand_id
=brands
.id
Inner joinsections
onvehicles
.section_id
=sections
.id
Limit 4 offset 0) Line 620
What am I doing wrong?
source to share
You should use selectRaw()
instead select()
:
->selectRaw('vehicles.*, vehicles.id AS vid');
More on raw expressions: http://laravel.com/docs/5.0/queries#raw-expressions
source to share