update network moudle
This commit is contained in:
@@ -11,6 +11,7 @@ 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
|
||||
{
|
||||
@@ -18,35 +19,37 @@ 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']
|
||||
],
|
||||
['host.datacenter.vCenter']
|
||||
);
|
||||
$title = 'List all network';
|
||||
|
||||
return view('admin.package.network.index',compact('networks','title'));
|
||||
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');
|
||||
return back()->with('success', 'The process is being established, please wait');
|
||||
}
|
||||
public function create()
|
||||
{
|
||||
$title = 'Add Network';
|
||||
|
||||
return view('admin.package.network.add', compact('title'));
|
||||
return view('administrator.pages.package.network.add', compact('title'));
|
||||
}
|
||||
public function store(NetworkRequest $request)
|
||||
{
|
||||
$request->validated();
|
||||
$host = $this->hostRepository->find($request->get('module_host_id'));
|
||||
if (! $host) {
|
||||
if (!$host) {
|
||||
return back()->withErrors('Invalid Request');
|
||||
}
|
||||
$isCreated = $this->networkRepository->findBy('network', $request->get('network'));
|
||||
@@ -66,19 +69,19 @@ class Network extends Controller
|
||||
public function edit(int $id = 0)
|
||||
{
|
||||
$network = $this->networkRepository->findWithRelationships($id, ['host.datacenter']);
|
||||
if (! $network) {
|
||||
if (!$network) {
|
||||
return back()->withErrors('Invalid Request');
|
||||
}
|
||||
$title = "View Network Information";
|
||||
|
||||
return view('admin.package.network.edit', compact('network', 'title'));
|
||||
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) {
|
||||
if (!$host) {
|
||||
return redirect()->route('package.network.index')->withErrors('Invalid Request');
|
||||
}
|
||||
if ($request->get('network') !== $host->network) {
|
||||
@@ -101,7 +104,7 @@ class Network extends Controller
|
||||
{
|
||||
$host = $this->networkRepository->find($id);
|
||||
|
||||
if (! $host) {
|
||||
if (!$host) {
|
||||
return back()->withErrors('Invalid request.');
|
||||
}
|
||||
|
||||
@@ -115,4 +118,28 @@ class Network extends Controller
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user