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

vandyahm24's avatar

how to group data with EAV (entity attribute value) tables in laravel

hello everyone i have an eav table like this

id |vendor_id |client_detail_name|client_detail_value| 1 | 1 | vendor_id | 1 | 2 | 1 |major_name | freeport | 3 | 1 |categori | gold | 4 | 1 |vendor_status | active | 5 | 1 |vendor_id | 1 | 6 | 1 |major_name | aqua | 7 | 1 |categori | water | 8 | 1 |vendor_status | active | 9 | 1 |vendor_id | 1 | 10 | 1 |major_name | samsung | 11 | 1 |categori | electronic | 12 | 1 |vendor_status | nonactive | I have a table like that, I deliberately added vendor_id in client_detail_name to delimiter data , and each data always has 4 enitity, namely:

vendor_id major_name category vendor_status How do I change the table to be like the following array?

0 => {#1235 +"vendor_id": 1 +"major_name": freeport +"categori": gold +"vendor_status": active } 1 => {#1222 +"vendor_id": 1 +"major_name": aqua +"categori": water +"vendor_status": active } 2 => {#1222 +"vendor_id": 1 +"major_name": samsung +"categori": electronic +"vendor_status": nonactive }

0 likes
1 reply
bugsysha's avatar

@vandyahm24 can you format this so it is readable?

What ever you want to transform to some other format you can use map method on a collection and do transformations there.

Please or to participate in this conversation.