update
This commit is contained in:
@@ -14,21 +14,74 @@ use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class Host extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public HostRepositoryInterface $hostRepository,
|
||||
public DatacenterRepositoryInterface $datacenterRepository
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hosts = $this->hostRepository->filter([
|
||||
'page' => $request->get('page') ?? 1
|
||||
], ['datacenter.vCenter']);
|
||||
$title = 'List all Host';
|
||||
return view("admin.package.host.index", compact('hosts', 'title'));
|
||||
return view("admin.package.host.index", compact('title'));
|
||||
}
|
||||
|
||||
public function datatable(Request $request)
|
||||
{
|
||||
$query = $this->hostRepository->filter(
|
||||
$request->all(),
|
||||
['datacenter.vCenter'],
|
||||
[],
|
||||
['*'],
|
||||
true
|
||||
);
|
||||
|
||||
return DataTables::eloquent($query)
|
||||
->editColumn('updated_at', function ($d) {
|
||||
return $d->updated_at ? $d->updated_at->format('d/m/Y') : '';
|
||||
})
|
||||
->addColumn('action', function ($d) {
|
||||
$editUrl = route('package.host.edit', ['id' => $d->id]);
|
||||
$deleteBtn = '';
|
||||
|
||||
if (auth()->guard('admins')->user()->can("delete module vcenter")) {
|
||||
$deleteUrl = route('package.host.destroy', ['id' => $d->id]);
|
||||
$csrf = csrf_field();
|
||||
$method = method_field('delete');
|
||||
$deleteBtn = <<<HTML
|
||||
<form method="post" action="$deleteUrl" class="d-inline">
|
||||
$method
|
||||
$csrf
|
||||
<button type="submit" class="btn btn-danger btn-sm" data-toggle="tooltip" title="Delete">
|
||||
<i data-lucide="trash-2" class="icon-sm"></i>
|
||||
</button>
|
||||
</form>
|
||||
HTML;
|
||||
}
|
||||
|
||||
return <<<HTML
|
||||
<a href="$editUrl" class="btn btn-warning btn-sm me-1" data-toggle="tooltip" title="Edit">
|
||||
<i data-lucide="edit" class="icon-sm"></i>
|
||||
</a>
|
||||
$deleteBtn
|
||||
HTML;
|
||||
})
|
||||
->filterColumn('datacenter.name', function ($query, $keyword) {
|
||||
$query->whereHas('datacenter', function ($q) use ($keyword) {
|
||||
$q->where('name', 'like', "%{$keyword}%");
|
||||
});
|
||||
})
|
||||
->filterColumn('datacenter.v_center.host', function ($query, $keyword) {
|
||||
$query->whereHas('datacenter.vCenter', function ($q) use ($keyword) {
|
||||
$q->where('host', 'like', "%{$keyword}%");
|
||||
});
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
public function sync(SyncHost $syncHost)
|
||||
{
|
||||
@@ -45,7 +98,7 @@ class Host extends Controller
|
||||
{
|
||||
$request->validated();
|
||||
$datacenter = $this->datacenterRepository->find($request->get('module_datacenter_id'));
|
||||
if (! $datacenter) {
|
||||
if (!$datacenter) {
|
||||
return back()->withErrors('Invalid Request');
|
||||
}
|
||||
$isCreated = $this->hostRepository->findBy('host_id', $request->get('host_id'));
|
||||
@@ -65,19 +118,19 @@ class Host extends Controller
|
||||
public function edit(int $id = 0)
|
||||
{
|
||||
$host = $this->hostRepository->findWithRelationships($id, ['datacenter']);
|
||||
if (! $host) {
|
||||
if (!$host) {
|
||||
return back()->withErrors('Invalid Request');
|
||||
}
|
||||
$title = "View Host Information";
|
||||
|
||||
return view('admin.package.host.edit', compact('host', 'title'));
|
||||
return view('admin.package.host.edit', compact('host', 'title'));
|
||||
}
|
||||
public function update(int $id = 0, HostRequest $request)
|
||||
{
|
||||
|
||||
$request->validated();
|
||||
$host = $this->hostRepository->find($id);
|
||||
if (! $host) {
|
||||
if (!$host) {
|
||||
return redirect()->route('package.host.index')->withErrors('Invalid Request');
|
||||
}
|
||||
if ($request->get('host_id') !== $host->host_id) {
|
||||
@@ -100,7 +153,7 @@ class Host extends Controller
|
||||
{
|
||||
$host = $this->hostRepository->find($id);
|
||||
|
||||
if (! $host) {
|
||||
if (!$host) {
|
||||
return back()->withErrors('Invalid request.');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user