Files
portal-api/app/Repositories/Group/GroupCachedRepository.php
T
2025-07-24 16:18:27 +07:00

53 lines
1.6 KiB
PHP

<?php
namespace App\Repositories\Group;
use App\Repositories\BaseCachedRepository;
use Illuminate\Support\Facades\Cache;
class GroupCachedRepository extends BaseCachedRepository implements GroupRepositoryInterface
{
public function __construct(
public GroupRepository $groupRepository
)
{
parent::__construct();
}
public function getModel()
{
return $this->groupRepository->getModel();
}
public function getProduct(int $group_id = 0, int $type_id = 0)
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'type_id' => $type_id,
'group_id' => $group_id
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($type_id, $group_id) {
return $this->groupRepository->getProduct($group_id, $type_id);
});
}
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'filterItem' => [
'data' => $data,
'relationships' => $relationships,
'select' => $select,
'withCount' => $withCount
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) {
return $this->groupRepository->filter($data, $relationships, $withCount, $select);
});
}
public function findBySlugWithProduct(string $slug)
{
return $this->model->where('slug', $slug)->with(['hostings', 'vps'])->first();
}
}