56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Module\Datacenter;
|
|
|
|
use App\Models\ModuleDatacenter;
|
|
use App\Repositories\BaseRepository;
|
|
|
|
class DatacenterRepository extends BaseRepository implements DatacenterRepositoryInterface
|
|
{
|
|
public function getModel()
|
|
{
|
|
return ModuleDatacenter::class;
|
|
}
|
|
|
|
public function filter(
|
|
array $data = [],
|
|
array $relationships = [],
|
|
array $withCount = [],
|
|
array $select = ['*'],
|
|
bool $returnQuery = false
|
|
) {
|
|
$query = $this->model
|
|
->select($select)
|
|
->with($relationships);
|
|
|
|
if (!empty($data['vcenter_id'])) {
|
|
$query->where('vcenter_id', $data['vcenter_id']);
|
|
}
|
|
|
|
if (!empty($withCount)) {
|
|
$query->withCount($withCount);
|
|
}
|
|
|
|
if ($returnQuery) {
|
|
return $query;
|
|
}
|
|
|
|
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)) {
|
|
return false;
|
|
}
|
|
return $this->model->where($key, $value)->first();
|
|
}
|
|
}
|