where('category_id', $categoryId); } public function type($type) { $q = $this; switch ($type) { case 'top': $q->whereNull('parent_id'); break; case 'all': break; default: break; } return $q; } }