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,

As AS

from vehicles

inner join brands

on vehicles

. brand_id

= brands

. id

Inner join sections

on vehicles

. section_id

= sections

. id

Limit 4 offset 0) Line 620

What am I doing wrong?

+3


source to share


1 answer


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

+6


source







All Articles