update
This commit is contained in:
@@ -4,21 +4,17 @@ namespace App\Http\Controllers\admin\package;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Package\IPRequest;
|
||||
use App\Models\ModuleDatacenter;
|
||||
use App\Models\ModuleHost;
|
||||
use App\Models\ModuleIpAddress;
|
||||
use App\Models\ModuleNetwork;
|
||||
use App\Models\vCenter;
|
||||
use App\Repositories\Module\IpAddress\IpAddressRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class IPMapping extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public IpAddressRepositoryInterface $ipAddressRepository
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$listIP = $this->ipAddressRepository->filter(
|
||||
@@ -102,7 +98,7 @@ class IPMapping extends Controller
|
||||
$ipaddress = $this->ipAddressRepository->findWithRelationships($id, ['host.datacenter.vCenter']);
|
||||
|
||||
|
||||
if (! $ipaddress) {
|
||||
if (!$ipaddress) {
|
||||
return back()->withErrors('Can\'t find IP Address by ID #' . $id);
|
||||
}
|
||||
|
||||
@@ -116,7 +112,7 @@ class IPMapping extends Controller
|
||||
{
|
||||
$ipaddress = $this->ipAddressRepository->find($id);
|
||||
|
||||
if (! $ipaddress) {
|
||||
if (!$ipaddress) {
|
||||
return back()->withErrors('Can\'t find IP Address by ID #' . $id);
|
||||
}
|
||||
|
||||
@@ -142,9 +138,9 @@ class IPMapping extends Controller
|
||||
|
||||
public function destroy(int $id = 0)
|
||||
{
|
||||
$ipaddress = $this->ipAddressRepository->find($id);
|
||||
$ipaddress = $this->ipAddressRepository->find($id);
|
||||
|
||||
if (! $ipaddress) {
|
||||
if (!$ipaddress) {
|
||||
return back()->withErrors('Can\'t find IP Address by ID #' . $id);
|
||||
}
|
||||
|
||||
@@ -158,4 +154,28 @@ class IPMapping extends Controller
|
||||
}
|
||||
return back()->with('success', 'Deleted Successfully');
|
||||
}
|
||||
|
||||
public function datatable(Request $request)
|
||||
{
|
||||
$query = $this->ipAddressRepository->filter(
|
||||
$request->all(),
|
||||
['host.datacenter.vCenter'],
|
||||
[],
|
||||
['*'],
|
||||
true
|
||||
);
|
||||
|
||||
return DataTables::eloquent($query)
|
||||
->addColumn(
|
||||
'action',
|
||||
fn($d) =>
|
||||
'<a href="' . route('package.ipaddress.edit', $d->id) . '" class="btn btn-primary btn-sm">Edit</a>'
|
||||
)
|
||||
->filterColumn('host.datacenter.v_center.host', function ($query, $keyword) {
|
||||
$query->whereHas('host.datacenter.vCenter', function ($q) use ($keyword) {
|
||||
$q->where('host', 'like', "%{$keyword}%");
|
||||
});
|
||||
})
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,18 +122,10 @@ class OsVersion extends Controller
|
||||
return $d->getStatus();
|
||||
})
|
||||
->addColumn('action', function ($d) {
|
||||
$editBtn = '<a href="' . route('package.version.edit', $d->id) . '"
|
||||
class="btn btn-primary">
|
||||
<i data-lucide="edit" class="w-12px h-12px"></i>
|
||||
</a>';
|
||||
|
||||
$deleteBtn = '<button type="button"
|
||||
class="btn btn-danger"
|
||||
onclick="showDeleteModal(' . $d->id . ', \'' . addslashes($d->version) . '\')">
|
||||
<i data-lucide="trash-2" class="w-12px h-12px"></i>
|
||||
</button>';
|
||||
|
||||
return '<div class="btn-group" role="group">' . $editBtn . $deleteBtn . '</div>';
|
||||
return view('administrator.pages.package.version.datatable.action', [
|
||||
'id' => $d->id,
|
||||
'version' => $d->version
|
||||
])->render();
|
||||
})
|
||||
->filterColumn('host', function ($query, $keyword) {
|
||||
$query->whereHas('host', function ($q) use ($keyword) {
|
||||
|
||||
@@ -16,19 +16,32 @@ class IpAddressCachedRepository extends BaseCachedRepository implements IpAddres
|
||||
{
|
||||
return $this->ipAddressRepository->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->ipAddressRepository
|
||||
->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->ipAddressRepository->filter($data, $relationships, $withCount, $select);
|
||||
});
|
||||
|
||||
return Cache::remember(
|
||||
$cacheKey,
|
||||
$this->cacheTime,
|
||||
fn() =>
|
||||
$this->ipAddressRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery)
|
||||
);
|
||||
}
|
||||
public function updateBy(array $condistions = [], array $data = [])
|
||||
{
|
||||
@@ -36,7 +49,7 @@ class IpAddressCachedRepository extends BaseCachedRepository implements IpAddres
|
||||
$this->clearCache();
|
||||
return $this;
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = [])
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findWithRelationships' => [
|
||||
@@ -44,8 +57,8 @@ class IpAddressCachedRepository extends BaseCachedRepository implements IpAddres
|
||||
'relationships' => $relationships
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships,$withCount,$withSum) {
|
||||
return $this->ipAddressRepository->findWithRelationships($id, $relationships,$withCount,$withSum);
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships, $withCount, $withSum) {
|
||||
return $this->ipAddressRepository->findWithRelationships($id, $relationships, $withCount, $withSum);
|
||||
});
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
|
||||
@@ -11,23 +11,30 @@ class IpAddressRepository extends BaseRepository implements IpAddressRepositoryI
|
||||
{
|
||||
return ModuleIpAddress::class;
|
||||
}
|
||||
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)
|
||||
{
|
||||
$model = $this->model->with($relationships)->select($select);
|
||||
$query = $this->model->with($relationships)->select($select);
|
||||
|
||||
if (isset($data['status'])) {
|
||||
$model = $model->where("status", $data['status']);
|
||||
$query = $query->where("status", $data['status']);
|
||||
}
|
||||
if (isset($data['module_network_id']) && $data['module_network_id']) {
|
||||
$model = $model->where("module_network_id", $data['module_network_id']);
|
||||
$query->where("module_network_id", $data['module_network_id']);
|
||||
}
|
||||
if (count($withCount) > 0) {
|
||||
$model = $model->withCount($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 findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
|
||||
@@ -6,9 +6,15 @@ use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface IpAddressRepositoryInterface 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 updateBy(array $condistions = [], array $data = []);
|
||||
public function findBy(string $key = '',string|int|null $value = '' );
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = []);
|
||||
public function findBy(string $key = '', string|int|null $value = '');
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = []);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user