- Changed view extends from "admin.main" to "administrator.layout.master" across multiple files. - Updated route names in admin.php and administrator.php to reflect new structure for user, order, invoice, and other management functionalities. - Adjusted view includes to point to the new directory structure for blocks and components. - Ensured all permission checks remain intact while refactoring the views.
146 lines
4.8 KiB
PHP
146 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\admin\package;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Package\NetworkRequest;
|
|
use App\Jobs\VirtualMachine\Sync\SyncNetwork;
|
|
use App\Models\ModuleNetwork;
|
|
use App\Repositories\Module\Host\HostRepositoryInterface;
|
|
use App\Repositories\Module\Network\NetworkRepositoryInterface;
|
|
use Exception;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
|
|
class Network extends Controller
|
|
{
|
|
//
|
|
public function __construct(
|
|
public NetworkRepositoryInterface $networkRepository,
|
|
public HostRepositoryInterface $hostRepository
|
|
) {
|
|
}
|
|
public function index(Request $request)
|
|
{
|
|
$networks = $this->networkRepository->filter(
|
|
[
|
|
'page' => $request->get('page') ?? 1
|
|
],
|
|
['host.datacenter.vCenter']
|
|
);
|
|
$title = 'List all network';
|
|
|
|
return view('administrator.pages.package.network.index', compact('networks', 'title'));
|
|
}
|
|
|
|
public function sync(SyncNetwork $syncNetwork)
|
|
{
|
|
dispatch($syncNetwork)->delay(now()->addSeconds(5));
|
|
return back()->with('success', 'The process is being established, please wait');
|
|
}
|
|
public function create()
|
|
{
|
|
$title = 'Add Network';
|
|
|
|
return view('administrator.pages.s.package.network.add', compact('title'));
|
|
}
|
|
public function store(NetworkRequest $request)
|
|
{
|
|
$request->validated();
|
|
$host = $this->hostRepository->find($request->get('module_host_id'));
|
|
if (!$host) {
|
|
return back()->withErrors('Invalid Request');
|
|
}
|
|
$isCreated = $this->networkRepository->findBy('network', $request->get('network'));
|
|
if ($isCreated) {
|
|
return back()->withErrors('The Network ID already exists');
|
|
}
|
|
DB::beginTransaction();
|
|
try {
|
|
$this->networkRepository->create($request->all());
|
|
DB::commit();
|
|
} catch (Exception $error) {
|
|
DB::rollBack();
|
|
return back()->withErrors($error->getMessage());
|
|
}
|
|
return redirect()->route('package.network.index')->with('success', 'Add new Network successfully');
|
|
}
|
|
public function edit(int $id = 0)
|
|
{
|
|
$network = $this->networkRepository->findWithRelationships($id, ['host.datacenter']);
|
|
if (!$network) {
|
|
return back()->withErrors('Invalid Request');
|
|
}
|
|
$title = "View Network Information";
|
|
|
|
return view('administrator.pages.package.network.edit', compact('network', 'title'));
|
|
}
|
|
public function update(int $id = 0, NetworkRequest $request)
|
|
{
|
|
|
|
$request->validated();
|
|
$host = $this->networkRepository->find($id);
|
|
if (!$host) {
|
|
return redirect()->route('package.network.index')->withErrors('Invalid Request');
|
|
}
|
|
if ($request->get('network') !== $host->network) {
|
|
$isCreated = $this->networkRepository->findBy('network', $request->get('network'));
|
|
if ($isCreated) {
|
|
return back()->withErrors('The Network ID already exists');
|
|
}
|
|
}
|
|
try {
|
|
DB::beginTransaction();
|
|
$this->networkRepository->update($id, $request->all());
|
|
DB::commit();
|
|
} catch (Exception $exception) {
|
|
DB::rollBack();
|
|
return back()->withErrors($exception->getMessage());
|
|
}
|
|
return redirect()->route('package.network.index')->with('success', 'Update successfully');
|
|
}
|
|
public function destroy(int $id = 0)
|
|
{
|
|
$host = $this->networkRepository->find($id);
|
|
|
|
if (!$host) {
|
|
return back()->withErrors('Invalid request.');
|
|
}
|
|
|
|
DB::beginTransaction();
|
|
try {
|
|
$this->networkRepository->delete($id);
|
|
DB::commit();
|
|
} catch (Exception $error) {
|
|
DB::rollBack();
|
|
return back()->withErrors($error->getMessage());
|
|
}
|
|
return redirect()->route('package.network.index')->with('success', 'Deleted successfully!');
|
|
}
|
|
|
|
public function datatable(Request $request)
|
|
{
|
|
$query = $this->networkRepository->filter(
|
|
$request->all(),
|
|
['host.datacenter.vCenter'],
|
|
[],
|
|
['*'],
|
|
true
|
|
);
|
|
|
|
return DataTables::eloquent($query)
|
|
->addColumn(
|
|
'action',
|
|
fn($d) =>
|
|
'<a href="' . route('package.network.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);
|
|
}
|
|
}
|