update sync vm
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\VirtualMachine;
|
||||
|
||||
use App\Models\VirtualMachines;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class VirtualMachineRepository extends BaseRepository implements VirtualMachineRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return VirtualMachines::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['datacenter_id'])) {
|
||||
$query->where('datacenter_id', $data['datacenter_id']);
|
||||
}
|
||||
|
||||
if (!empty($data['host_id'])) {
|
||||
$query->where('host_id', $data['host_id']);
|
||||
}
|
||||
|
||||
if (!empty($data['name'])) {
|
||||
$query->where('name', 'like', '%' . $data['name'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($withCount)) {
|
||||
$query->withCount($withCount);
|
||||
}
|
||||
|
||||
if ($returnQuery) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
if (!empty($data['paginate']) || !empty($data['page'])) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\VirtualMachine;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface VirtualMachineRepositoryInterface extends BaseRepositoryInterface {
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user