37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Discount;
|
|
|
|
use App\Repositories\BaseCachedRepository;
|
|
use App\Support\Cache\CacheKey;
|
|
|
|
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 = ['*'])
|
|
{
|
|
return $this->rememberFilter(
|
|
compact('data', 'relationships', 'withCount', 'select'),
|
|
fn() => $this->discountRepository->filter($data, $relationships, $withCount, $select)
|
|
);
|
|
}
|
|
public function findBy(string $key = '', string $value = '')
|
|
{
|
|
if (empty($value) || empty($key)) {
|
|
return false;
|
|
}
|
|
$cacheKey = CacheKey::build($this->getModuleName(), 'find-by', ['key' => $key, 'value' => $value]);
|
|
return $this->cache->remember($cacheKey, function () use ($key, $value) {
|
|
return $this->model->where($key, $value)->first();
|
|
});
|
|
}
|
|
}
|