update
This commit is contained in:
@@ -16,18 +16,23 @@ class HostCachedRepository extends BaseCachedRepository implements HostRepositor
|
||||
{
|
||||
return $this->hostRepository->getModel();
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
||||
{
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
if ($returnQuery || isset($data['page']) || isset($data['paginate'])) {
|
||||
return $this->hostRepository->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||
}
|
||||
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'filterItem' => [
|
||||
'data' => $data,
|
||||
'relationships' => $relationships,
|
||||
'select' => $select,
|
||||
'withCount' => $withCount
|
||||
]
|
||||
'filter' => compact('data', 'relationships', 'withCount', 'select')
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) {
|
||||
return $this->hostRepository->filter($data, $relationships, $withCount, $select);
|
||||
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount, $returnQuery) {
|
||||
return $this->hostRepository->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||
});
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = [])
|
||||
|
||||
@@ -12,23 +12,32 @@ class HostRepository extends BaseRepository implements HostRepositoryInterface
|
||||
return ModuleHost::class;
|
||||
}
|
||||
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
||||
{
|
||||
$model = $this->model->with($relationships)->select($select);
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
$query = $this->model->with($relationships)->select($select);
|
||||
|
||||
if (isset($data['module_datacenter_id']) && $data['module_datacenter_id']) {
|
||||
$model = $model->where("module_datacenter_id", $data['module_datacenter_id']);
|
||||
$query = $query->where("module_datacenter_id", $data['module_datacenter_id']);
|
||||
}
|
||||
|
||||
if (count($withCount) > 0) {
|
||||
$model = $model->withCount($withCount);
|
||||
$query = $query->withCount($withCount);
|
||||
}
|
||||
|
||||
if (isset($data['page'])) {
|
||||
return $model->paginate(15);
|
||||
if ($returnQuery) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $model->get();
|
||||
if (isset($data['page']) || isset($data['paginate'])) {
|
||||
return $query->paginate($data['per_page'] ?? 15);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
|
||||
@@ -4,7 +4,13 @@ namespace App\Repositories\Module\Host;
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface HostRepositoryInterface extends BaseRepositoryInterface{
|
||||
public function filter(array $data = [],array $relationships = [],array $withCount = [],array $select = ['*']);
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = []);
|
||||
public function findBy(string $key = '',string|int|null $value = '' );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user