Edit File: CategoryService.php
<?php namespace App\Services; use App\Models\Category; class CategoryService extends BaseService { public function __construct() { $this->model = Category::class; parent::__construct($this->model); } public function all($paginateNum = 10, $id = null) { $categories = $this->model::where('parent_id', $id)->search(request()->searchArray)->paginate($paginateNum); $level = $this->find($id)?->level; return ['key' => 'success', 'msg' => __('apis.success'), 'data' => ['categories' => $categories, 'level' => $level]]; } public function getListOfCategoriesWithoutPagination($id = null) { $categories = $this->model::active()->where('parent_id', $id)->withCount('childes')->get(); return ['key' => 'success', 'msg' => __('apis.success'), 'data' => ['categories' => $categories]]; } public function getAllParentCategories() { return $this->model::active()->whereNull('parent_id')->get(); } public function getAllParentCategoriesHasChilds() { return $this->model::active()->whereNull('parent_id')->has('childes')->get(); } public function getAll($category = null) { return $this->model::latest()->when($category->level && $category->level == 2, function ($q) { $q->whereNull('parent_id'); })->when($category->level && $category->level == 3, function ($q) use ($category) { $q->whereId($category->parent_id)->whereHas('parent', function ($q) { $q->whereNull('parent_id'); }); })->get(); } // Used inside Provider Dashboard public function getListOfSubCategoriesForProviders() { return auth('provider')->user()->subCategories()->whereHas('childes')->withCount('childes')->get(); } // Used inside Provider Dashboard public function getListOfSubCategoriesWithOutPagination($id = null) { return $this->model::active()->where('parent_id', $id)->get(); } }
Back to File Manager