find($id); } public function create(CityBranchAttr $cityBranchAttr) { $res = CityBranch::create([ 'name' => $cityBranchAttr->getName(), 'city_id' => $cityBranchAttr->getCityId(), 'city_center_id' => $cityBranchAttr->getCityCenterId() ]); return $res; } public function delete($id) { $res = CityBranch::find($id); $res->delete(); return $res; } public function update($id, CityBranchAttr $cityBranchAttr) { $res = CityBranch::find($id); $res->update([ 'name' => $cityBranchAttr->getName(), 'city_id' => $cityBranchAttr->getCityId() ]); return $res; } public function findByCity($cityId, $serviceCategoryId) { return CityBranch::where('city_id', $cityId)->where('service_category_id', $serviceCategoryId)->first(); } public function findByCityCenterId($cityCenterId, $serviceCategoryId) { return CityBranch::where('city_center_id', $cityCenterId)->where('service_category_id', $serviceCategoryId)->first(); } public function select2ByServiceCategory(?string $search, $serviceCategoryId): PaginateCollectionAttr { $auth = Auth::guard('jwt_mobile')->user() ?? Auth::user(); $cityBranchId = []; foreach ($auth->userRole->role->cityBranches ?? [] as $cityBranch) { $cityBranchId[] = $cityBranch->id; } if (getAuthRoleName() === 'super admin') { $cityBranch = CityBranch::select('id', 'name as text', 'name as label')->where('service_category_id', $serviceCategoryId)->withoutGlobalScope('syncActiveServiceCategory')->orderBy('id', 'ASC'); } else { $cityBranch = CityBranch::select('id', 'name as text', 'name as label')->where('service_category_id', $serviceCategoryId)->whereIn('id', $cityBranchId)->withoutGlobalScope('syncActiveServiceCategory')->orderBy('id', 'ASC'); } return (new PaginateCollectionAttrBuilder) ->build( $cityBranch, (new PaginateBuilderAttr)->setSearchKeyword($search), new PaginateSchemaCityBranch ); } public function select2WhereNotActive(?string $search): PaginateCollectionAttr { return (new PaginateCollectionAttrBuilder) ->build( CityBranch::select('id', 'name as text', 'name as label'), (new PaginateBuilderAttr)->setSearchKeyword($search), new PaginateSchemaCityBranch ); } public function listByServiceCategory($serviceCategoryId) { return CityBranch::select('id', 'city_id', 'city_center_id', 'name as label', 'service_category_id')->where('service_category_id', $serviceCategoryId)->withoutGlobalScope('syncActiveServiceCategory')->get(); } }