Laravel 5 SQLSTATE[42S22]: 找不到列

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 'vehicles.model,' in '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

我做错了什么?

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

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

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