Update source into github
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Setting;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class SettingCachedRepository extends BaseCachedRepository implements SettingRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public SettingRepository $settingRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->settingRepository->getModel();
|
||||
}
|
||||
public function getByKey(string $key = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey('setting_getByKey:'.$key);
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key) {
|
||||
return $this->settingRepository->getByKey($key);
|
||||
});
|
||||
}
|
||||
public function updateOrCreateByKey(string $key, array $data = [])
|
||||
{
|
||||
$this->clearCacheByKey($key);
|
||||
return $this->settingRepository->updateOrCreateByKey($key, $data);
|
||||
}
|
||||
|
||||
public function clearCacheByKey(string $key)
|
||||
{
|
||||
$cacheKey = $this->getCacheKey("setting_getByKey:{$key}");
|
||||
Cache::forget($cacheKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Setting;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class SettingRepository extends BaseRepository implements SettingRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return Setting::class;
|
||||
}
|
||||
public function getByKey(string $key = '')
|
||||
{
|
||||
$results = $this->model->where('key', $key)->first();
|
||||
return $results ? $results->value : null;
|
||||
}
|
||||
public function updateOrCreateByKey(string $key, array $data = [])
|
||||
{
|
||||
|
||||
return $this->model->updateOrCreate(
|
||||
[
|
||||
'key' => $key
|
||||
],
|
||||
$data
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace App\Repositories\Setting;
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface SettingRepositoryInterface extends BaseRepositoryInterface
|
||||
{
|
||||
public function getByKey(string $key = '');
|
||||
public function updateOrCreateByKey(string $key, array $data = []);
|
||||
}
|
||||
Reference in New Issue
Block a user