Support the ongoing development of Laravel.io →
Configuration Input Database
Last updated 2 years ago.
0
moderator

I should load the subcategories to the parent category, in this example I suspect a relation called children

$catecories = Category::whereNull('parent_id')->with('children')->get();

And in your blade

@foreach ($categories as $category)
    //html before the subcategories
    @foreach($category->children as $subcategory)
        // the html for the subcategory
    @endforeach
    //html after the subcategories
@endforeach

Edit:
No I read your post again this is maybe not directly an answer to your question. My html/css skills aren't good so I can't help you with that. But because I think the example I give is a improvement of the code I don't remove it.

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.