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,如AS从vehicles内连接brands上vehicles.brand_id=brands.id内连接sections上vehicles.section_id=sections.id限制4偏移0)620线
我做错了什么?
您应该使用selectRaw()而不是select():
->selectRaw('vehicles.*, vehicles.id AS vid');
Run Code Online (Sandbox Code Playgroud)
阅读有关原始表达式的更多信息:http://laravel.com/docs/5.0/queries#raw-expressions