50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Discount;
|
|
|
|
use App\Repositories\BaseCachedRepository;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class DiscountCachedRepository extends BaseCachedRepository implements DiscountRepositoryInterface
|
|
{
|
|
public function __construct(
|
|
public DiscountRepository $discountRepository
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
public function getModel()
|
|
{
|
|
return $this->discountRepository->getModel();
|
|
}
|
|
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->discountRepository->filter($data, $relationships, $withCount, $select);
|
|
});
|
|
}
|
|
public function findBy(string $key = '', string $value = '')
|
|
{
|
|
$cacheKey = $this->getCacheKey(md5(json_encode([
|
|
'findBy' => [
|
|
'key' => $key,
|
|
'value' => $value
|
|
]
|
|
])));
|
|
if (empty($value) || empty($key)) {
|
|
return false;
|
|
}
|
|
return $this->model->where($key, $value)->first();
|
|
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value) {
|
|
return $this->discountRepository->findBy($key, $value);
|
|
});
|
|
}
|
|
}
|