这是我的SQL操作:
select `id_ifc_espaces`,GROUP_CONCAT(DISTINCT `nom_espace`) as nom_espace ,GROUP_CONCAT(DISTINCT `fonction_espace`) as fonction_espace, GROUP_CONCAT(DISTINCT `id_ouvrage_slab_wall`) as id_ouvrage_slab_wall , GROUP_CONCAT(DISTINCT `type_limit`) as type_limit,GROUP_CONCAT(DISTINCT `type_ouvr`) as type_ouvr from `relespouv` group by`id_ifc_espaces`
这是我尝试过的查询生成器:
$relations = DB::table('relespouv')
->select('id_ifc_espaces')
->group_by('id_ifc_espaces')
->where('id_mn','=',$idmn)
->get(array(DB::raw('GROUP_CONCAT(DISTINCT nom_espace) as nom_espace,
GROUP_CONCAT(DISTINCT fonction_espace) AS fonction_espace,
GROUP_CONCAT(DISTINCT id_ouvrage_slab_wall) AS id_ouvrage_slab_wall,
GROUP_CONCAT(DISTINCT type_limit) AS type_limit,
GROUP_CONCAT(DISTINCT type_ouvr) AS type_ouvr ')));
当我尝试使用例如nom_espace
时:
$relespouv[$allelement['Relation']][12]=$relation->nom_espace;
我收到错误:
未定义的属性:stdClass :: $ nom_espace
任何人都可以帮助我吗?
答案 0 :(得分:3)
你应该移动
array(DB::raw('GROUP_CONCAT(DISTINCT nom_espace) as nom_espace,
GROUP_CONCAT(DISTINCT fonction_espace) AS fonction_espace,
GROUP_CONCAT(DISTINCT id_ouvrage_slab_wall) AS id_ouvrage_slab_wall,
GROUP_CONCAT(DISTINCT type_limit) AS type_limit,
GROUP_CONCAT(DISTINCT type_ouvr) AS type_ouvr ')
)
从get()
到select()
就像这样
$relations = DB::table('relespouv')
->select(array(
'id_ifc_espaces'
DB::raw('GROUP_CONCAT(DISTINCT nom_espace) as nom_espace,
GROUP_CONCAT(DISTINCT fonction_espace) AS fonction_espace,
GROUP_CONCAT(DISTINCT id_ouvrage_slab_wall) AS id_ouvrage_slab_wall,
GROUP_CONCAT(DISTINCT type_limit) AS type_limit,
GROUP_CONCAT(DISTINCT type_ouvr) AS type_ouvr ')
))
->group_by('id_ifc_espaces')
->where('id_mn','=',$idmn)
->get();