我正在做一些连接,并试图获得数据。我的查询生成器是:
$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
vehicles
。model,
作为AS
由vehicles
内连接brands
到vehicles
。brand_id
=brands
。id
内连接sections
到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