Laravel 5 SQLSTATE[42S22]: Column not found

三世轮回 提交于 2019-12-23 14:51:25

问题


I am doing some joins and trying to get the data. My query builder is:

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

But i am getting this error:

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

What i am doing wrong ?


回答1:


You should use selectRaw() instead of select():

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

Read more about raw expressions: http://laravel.com/docs/5.0/queries#raw-expressions



来源:https://stackoverflow.com/questions/30507162/laravel-5-sqlstate42s22-column-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!