I have this table structure below
TABLE VIEW
+------+---------------+---------------+---------------+
|id | group_name | sub_group | title |
+------+---------------+---------------+---------------+
|1 | Mobile Phone | Apple | Iphone X |
|2 | Mobile Phone | Apple | Iphone 7 Plus|
|3 | Mobile Phone | Samsung | J6 Plus |
|4 | Mobile Phone | Nokia | XpressMusic |
+------+---------------+---------------+---------------+
How to loop this table and store in an array and look like this
LOOP
Mobile Phone
-> Apple
-> Iphone X
-> Iphone 7 Plus
-> Samsung
-> J6 Plus
-> Nokia
-> XpressMusic
This is my code using eloquent, I've run a distinct under group_name sub_group but I have no idea how am I gonna get the title based on group_name
and sub_group
$group_names = ThisIsModel::distinct()->orderBy('group_name', 'asc')->get(['group_name']);
I don't know what to do next. Please help me. Thanks