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

superhrk's avatar

How to Relationship/join Three Level tables for Category & echo Tree View in Blade template ?

Hi friends I am new to laravel 5, I need your help to show three level tree view category look like this

Laptop & Computers >    //if clicked than show categories groups in dropdown <li>
------------------
        Laptops
        Computers > //if clicked than show sub categories dropdown <li>
        ---------
            Dell
            HP
            ---

Here is all the details may help......

1 - Tables Schema

categories
    id - integer
    name - string

subcatgroups
    id - integer
    name - string
    cat_id- integer     // foreign key for categories id

subcats
    id - integer
    name - string
    sub_gid- integer    // foreign key for subcatgroups id
0 likes
3 replies
superhrk's avatar

@JarekTkaczyk thanks for reply, did you explain how i can resolve this issue in the scence of above particular data table ?

superhrk's avatar
superhrk
OP
Best Answer
Level 1

thank God issue has been resolved :)

class Category extends Eloquent {
    protected $appends = ['subcat']; // only available in Laravel 5

    public function getSubcatAttribute() {
        return $this->subcatgroup->subcat;
    }
}

Please or to participate in this conversation.