How to get sub categories of category in laravel

Getting Sub Categories of a Category in laravel

Example models,

app/models/Category.php

<?php

class Category extends Eloquent
{
    /**
     * This will relate the current category to the categories having parent_id value as $this->id
     */
    public function children()
    {
        return $this->hasMany('Category', 'parent_id');
    }
}

Leave a Reply