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

Tar*_*tar 4 php sql join query-builder laravel

我正在做一些连接并尝试获取数据.我的查询构建器是:

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

但我得到这个错误:

SQLSTATE [42S22]:柱未找到:在'字段列表' 1054未知列'vehicles.model,'(SQL:选择vehicles.model,ASvehicles内连接brandsvehicles.brand_id= brands.id内连接sectionsvehicles.section_id= sections.id限制4偏移0)620线

我做错了什么?

Lim*_*nte 7

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

->selectRaw('vehicles.*, vehicles.id AS vid');
Run Code Online (Sandbox Code Playgroud)

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