Do you mean change the structure to how yours look (array form). Or output it in html? Or? A filter makes little sense with what you have shown
Mar 3, 2020
6
Level 3
How to create a filter from an Array?
Array
(
[0] = Array
(
[main_catg] = Home Appliances
[sub_catg] = Coffee Makers
[child_catg] = Arabic
)
[2] = Array
(
[main_catg] = Food
[sub_catg] = Coffee & Tea
[child_catg] = Arabic Coffee
)
[3] = Array
(
[main_catg] = Home Appliances
[sub_catg] = Coffee Makers
[child_catg] = Turkish
)
[4] = Array
(
[main_catg] = Food
[sub_catg] = Coffee & Tea
[child_catg] = Turkish Coffee
)
)
How to get filter as below from the above array?
- Home Appliances
- Coffee Makers
- Arabic
- Turkish
- Food
- Coffee & Tea
- Arabic Coffee
- Turkish Coffee
I am not an expert in coding, I tried many ways to get this result. Any Suggestions? Thanks in Advance.
Level 102
Ok then you need the right structure that you can loop over
$final = collect($array)->groupBy(['main_catg', 'sub_catg']);
dd($final);
And blade (made from memory so might need tweaking)
@foreach ($final as $main_catg => $sub)
{{$main_catg}}
@foreach ($sub as $sub_catg => $items)
{{sub_catg}}
@foreach ($items as $item)
{{item['child_catg']}}
@endforeach
@endforeach
@endforeach
1 like
Please or to participate in this conversation.