update datatable
This commit is contained in:
@@ -16,19 +16,32 @@ class DatacenterCachedRepository extends BaseCachedRepository implements Datacen
|
||||
{
|
||||
return $this->datacenterRepository->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 ||
|
||||
!empty($data['paginate'])
|
||||
) {
|
||||
return $this->datacenterRepository
|
||||
->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->datacenterRepository->filter($data, $relationships, $withCount, $select);
|
||||
});
|
||||
|
||||
return Cache::remember(
|
||||
$cacheKey,
|
||||
$this->cacheTime,
|
||||
fn() =>
|
||||
$this->datacenterRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery)
|
||||
);
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
|
||||
@@ -12,22 +12,39 @@ class DatacenterRepository extends BaseRepository implements DatacenterRepositor
|
||||
return ModuleDatacenter::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
|
||||
->select($select)
|
||||
->with($relationships);
|
||||
|
||||
if (isset($data['vcenter_id']) && $data['vcenter_id']) {
|
||||
$model = $model->where("vcenter_id", $data['vcenter_id']);
|
||||
if (!empty($data['vcenter_id'])) {
|
||||
$query->where('vcenter_id', $data['vcenter_id']);
|
||||
}
|
||||
if (count($withCount) > 0) {
|
||||
$model = $model->withCount($withCount);
|
||||
|
||||
if (!empty($withCount)) {
|
||||
$query->withCount($withCount);
|
||||
}
|
||||
if (isset($data['page'])) {
|
||||
return $model->paginate(15);
|
||||
|
||||
if ($returnQuery) {
|
||||
return $query;
|
||||
}
|
||||
return $model->get();
|
||||
|
||||
if (!empty($data['paginate'])) {
|
||||
return $query->paginate(
|
||||
$data['per_page'] ?? 15
|
||||
);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
if (empty($key) || empty($value)) {
|
||||
|
||||
@@ -3,7 +3,15 @@ namespace App\Repositories\Module\Datacenter;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface DatacenterRepositoryInterface extends BaseRepositoryInterface{
|
||||
public function filter(array $data = [],array $relationships = [],array $withCount = [],array $select = ['*']);
|
||||
public function findBy(string $key = '',string|int|null $value = '' );
|
||||
interface DatacenterRepositoryInterface extends BaseRepositoryInterface
|
||||
{
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
|
||||
public function findBy(string $key = '', string|int|null $value = '');
|
||||
}
|
||||
Reference in New Issue
Block a user