This commit is contained in:
pbao9
2026-02-03 11:07:47 +07:00
parent 0f9b6ffef2
commit 6178a76eee
18 changed files with 347 additions and 420 deletions
@@ -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);
}
}