日志含义SQLSTATE[42S22]: Column not found


Laravel 5 SQLSTATE[42S22]: Column not found

我正在做一些连接,并试图获得数据。我的查询生成器是:

$datasource = DB::table('vehicles')->join('brands', 'vehicles.brand_id', '=', 'brands.id')->join('sections', 'vehicles.section_id', '=', 'sections.id')->select('vehicles.*, vehicles.id AS vid');

但是我得到这个错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown Column .日志含义的车辆。model,' in 'field list' (SQL: select vehiclesmodel,作为ASvehicles内连接brandsvehiclesbrand_id =brandsid内连接sectionsvehiclessection_id =sectionsid limit 4 offset 0) Line 620

您应该使用selectRaw()而不是select():

->selectRaw('vehicles.*, vehicles.id AS vid');

阅读更多关于原始表达式的信息:http://laravel.com/docs/5.0/queries#raw-expressions