YOSRA BEN SALAH
YOSRA BEN SALAH

Reputation: 35

Group_concat - query builder

This is my SQL operation:

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` 

This is Query Builder that I tried:

$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 ')));

When I try to use for example nom_espace:

 $relespouv[$allelement['Relation']][12]=$relation->nom_espace;

I get the error:

Undefined property: stdClass::$nom_espace

Can any one help me please?

Upvotes: 3

Views: 5745

Answers (1)

Limon Monte
Limon Monte

Reputation: 54379

You should move

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 ')
)

from get() to select() like this

$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();

Upvotes: 3

Related Questions