Skip to content
Advertisement

Laravel Multilayered groupBy

Assume we have this record:

JavaScript

While assuming we have this code in our DummyController:

JavaScript

And lastly, assuming we have @foreach ($dummyRecord as $dummy_column_name => $dummy) inside our index.blade, we could display the result as such:

JavaScript

But I want to display the relation 4‘s record of color as a div inside a div, which makes the final output look like this inside the index.blade file:

JavaScript

Should I use another groupBy to sort the record of colors, or is there another sorting code I could add inside the index.blade file?

Advertisement

Answer

You can group by multiple nested properties like that:

JavaScript

And loop over it in your blade like that:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement