app\Category::scopeChildsOf PHP Method

scopeChildsOf() public method

scopeChildsOf Return all the children of a category. If the id is empty, 'parents' or 'others' will be given.
public scopeChildsOf ( $query, $id )
$query
$id that can be either category id, empty value, 'parents' or 'mothers'
    public function scopeChildsOf($query, $id)
    {
        if (!$id || $id == 'parent' || $id == 'mothers') {
            return $query->whereNull('category_id');
        } else {
            return $query->where('category_id', $id);
        }
    }