⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
dalily.dev-unit.com
/
app
/
Services
/
View File Name :
CountryService.php
<?php /* * LaraClassifier - Classified Ads Web Application * Copyright (c) BeDigit. All Rights Reserved * * Website: https://laraclassifier.com * Author: Mayeul Akpovi (BeDigit - https://bedigit.com) * * LICENSE * ------- * This software is provided under a license agreement and may only be used or copied * in accordance with its terms, including the inclusion of the above copyright notice. * As this software is sold exclusively on CodeCanyon, * please review the full license details here: https://codecanyon.net/licenses/standard */ namespace App\Services; use App\Http\Resources\CountryResource; use App\Http\Resources\EntityCollection; use App\Models\Country; use App\Models\Scopes\ActiveScope; use App\Services\Country\itiTrait; use Illuminate\Http\JsonResponse; use Throwable; class CountryService extends BaseService { use itiTrait; /** * List countries * * @param array $params * @return \Illuminate\Http\JsonResponse */ public function getEntries(array $params = []): JsonResponse { $perPage = getNumberOfItemsPerPage('countries', $params['perPage'] ?? null, $this->perPage); $page = (int)($params['page'] ?? 1); $embed = getCommaSeparatedStrAsArray($params['embed'] ?? []); $keyword = $params['keyword'] ?? null; $isNonActiveIncluded = getIntAsBoolean($params['includeNonActive'] ?? 0); $isIti = getIntAsBoolean($params['iti'] ?? 0); $sort = $params['sort'] ?? []; // 'Intl Tel Input' countries list if ($isIti) { try { return $this->getItiCountries(); } catch (Throwable $e) { return apiResponse()->error($e->getMessage()); } } // Normal countries list // --- // Cache ID $cacheEmbedId = !empty($embed) ? '.embed.' . implode(',', $embed) : ''; $cacheFiltersId = '.filters.' . $keyword . (int)$isNonActiveIncluded; $cacheOrderById = !empty($this->columnWithOrder) ? '.sort.' . implode(',', $this->columnWithOrder) : ''; $cachePageId = '.page.' . $page . '.of.' . $perPage; $cacheId = 'countries.' . $cacheEmbedId . $cacheFiltersId . $cacheOrderById . $cachePageId; // Cached Query $countries = cache()->remember($cacheId, $this->cacheExpiration, function () use ( $perPage, $embed, $keyword, $isNonActiveIncluded, $sort ) { $countries = Country::query(); if (in_array('currency', $embed)) { $countries->with('currency'); } if (!empty($keyword)) { $countries->where('name', 'LIKE', '%' . $keyword . '%'); } if ($isNonActiveIncluded) { $countries->withoutGlobalScopes([ActiveScope::class]); } else { $countries->active(); } // Sorting $countries = $this->applySorting($countries, ['name', 'code'], $sort); return $countries->paginate($perPage); }); // If the request is made from the app's Web environment, // use the Web URL as the pagination's base URL $countries = setPaginationBaseUrl($countries); $resourceCollection = new EntityCollection(CountryResource::class, $countries, $params); $message = ($countries->count() <= 0) ? t('no_countries_found') : null; return apiResponse()->withCollection($resourceCollection, $message); } /** * Get country * * @param string $code * @param array $params * @return \Illuminate\Http\JsonResponse */ public function getEntry(string $code, array $params = []): JsonResponse { $embed = getCommaSeparatedStrAsArray($params['embed'] ?? []); // Cache ID $cacheEmbedId = !empty($embed) ? '.embed.' . implode(',', $embed) : ''; $cacheId = 'country.' . $code . $cacheEmbedId; // Cached Query $country = cache()->remember($cacheId, $this->cacheExpiration, function () use ($code, $embed) { $country = Country::query()->where('code', '=', $code); if (in_array('currency', $embed)) { $country->with('currency'); } return $country->first(); }); abort_if(empty($country), 404, t('country_not_found')); $resource = new CountryResource($country, $params); return apiResponse()->withResource($resource); } }