Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Umbus's avatar
Level 1

Query Json_arrayagg

Hello how can i make in eloquent this:

select json_object( 'name', l1.Name, 'children', JSON_ARRAYAGG(json_object('name', l2.Name, 'children', l2.children)) ) as json from infrastructures l1 left join ( select l2.name , l2.id_infrastructure , JSON_ARRAYAGG(json_object('name', l3.name)) as children from zones l2 left join locals l3 on l3.id_zone = l2.id group by l2.id ) l2 on l2.id_infrastructure = l1.id group by id

Thanks

0 likes
1 reply
a4ashraf's avatar

@umbus

well one thing, when you post a question using three tick sign " ` "

actually, you are using MariaDB (No SQL DB),

I'm not sure but for No SQL DB not need to use the Join

you should create a model and get data from the table and use Laravel collection for manipulate as per your requirement

Please or to participate in this conversation.