app\Category::getChildsAttribute PHP Method

getChildsAttribute() public method

Return a collection of a category's childs, or null if don't have.
public getChildsAttribute ( ) : collection
return collection
    public function getChildsAttribute()
    {
        $childs = $this->hasMany('App\\Category')->orderBy('name')->get();
        if (!count($childs)) {
            $childs = null;
        } elseif ($this->family_tree) {
            $childs->each(function ($cat) {
                $cat->withFamilyTree();
            });
        }
        return $childs;
    }