Update source into github

This commit is contained in:
pbao9
2025-07-24 16:18:27 +07:00
parent 41419358dd
commit 69851ac7bc
2642 changed files with 284095 additions and 0 deletions
@@ -0,0 +1,44 @@
<?php
namespace App\Repositories\Post;
use App\Repositories\BaseCachedRepository;
use Illuminate\Support\Facades\Cache;
class PostCachedRepository extends BaseCachedRepository implements PostRepositoryInterface
{
public function __construct(public PostRepository $postRepository)
{
parent::__construct();
}
public function getModel()
{
return $this->postRepository->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->postRepository->filter($data, $relationships, $withCount, $select);
});
}
public function findBy(string $key = '',string $value = '') {
$cacheKey = $this->getCacheKey(md5(json_encode([
'findBy' => [
'key' => $key,
'value' => $value,
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key,$value) {
return $this->postRepository->findBy($key,$value);
});
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Repositories\Post;
use App\Models\Post;
use App\Repositories\BaseRepository;
class PostRepository extends BaseRepository implements PostRepositoryInterface
{
public function getModel()
{
return Post::class;
}
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
{
$model = $this->model->with($relationships)->select($select);
if (isset($data['status']) && ! empty($data['status']) && $data['status'] != 'full') {
$model = $model->where("status", match (strtolower($data['status'])) {
'published' => 1,
'draft' => 2,
'pending' => 0,
});
}
if (count($withCount) > 0) {
$model = $model->withCount($withCount);
}
if (isset($data['limit']) && $data['limit']) {
return $model->latest('id')->take($data['limit'])->get();
}
if (isset($data['page']) && $data['page']) {
return $model->paginate(15);
}
return $model->get();
}
public function findBy(string $key = '',string $value = '') {
if(empty($key) || empty($value))
{
return false;
}
return $this->model->where($key,$value)->first();
}
}
@@ -0,0 +1,9 @@
<?php
namespace App\Repositories\Post;
use App\Repositories\BaseRepositoryInterface;
interface PostRepositoryInterface extends BaseRepositoryInterface {
public function filter(array $data = [],array $relationships = [],array $withCount = [],array $select = ['*']);
public function findBy(string $key = '',string $value = '');
}