This commit is contained in:
pbao9
2026-02-04 11:08:30 +07:00
parent 0b29522bd2
commit 8e4e0f33e3
9 changed files with 156 additions and 110 deletions
@@ -18,12 +18,14 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Facades\Excel;
use Yajra\DataTables\Facades\DataTables;
class ModulevCenterController extends Controller
{
public function __construct(
public vCenterRepositoryInterface $vCenterRepository
) {}
) {
}
// show all hosting module
public function index(Request $request)
{
@@ -37,7 +39,7 @@ class ModulevCenterController extends Controller
}
public function import(Request $request)
{
if (! $request->file) {
if (!$request->file) {
return back()->withErrors("Please choose your file");
}
$data = Excel::toArray([], $request->file);
@@ -55,7 +57,7 @@ class ModulevCenterController extends Controller
}
}
if (! isset($allData) || (isset($allData) && count($allData) < 1)) {
if (!isset($allData) || (isset($allData) && count($allData) < 1)) {
return back()->withErrors('No data imported');
}
@@ -86,7 +88,7 @@ class ModulevCenterController extends Controller
DB::beginTransaction();
try {
$data = $request->all();
$data['password'] = SignRSA::EncryptFunc($request->password);
$data['password'] = SignRSA::EncryptFunc($request->password);
$this->vCenterRepository->create($data);
DB::commit();
} catch (\Exception $error) {
@@ -98,14 +100,16 @@ class ModulevCenterController extends Controller
public function edit(int $id = 0)
{
$server = $this->vCenterRepository->find($id);
if (! $server) return back()->withErrors('Can\'t find server by id ' . $id);
if (!$server)
return back()->withErrors('Can\'t find server by id ' . $id);
$title = 'View vCenter information';
return view('administrator.pages.module.vcenter.edit', compact('title', 'server'));
}
public function update(UpdatevCenterRequest $request, int $id = 0)
{
$server = $this->vCenterRepository->find($id);
if (! $server) return back()->withErrors('Invalid Request');
if (!$server)
return back()->withErrors('Invalid Request');
$request->validated();
if ($request->get('host') != $server->name) {
$isExitsHost = $this->vCenterRepository->findByName($request->get('host'));
@@ -116,8 +120,8 @@ class ModulevCenterController extends Controller
DB::beginTransaction();
try {
$data = $request->all();
if (! empty($request->get('password'))) {
$data['password'] = SignRSA::EncryptFunc($request->password);
if (!empty($request->get('password'))) {
$data['password'] = SignRSA::EncryptFunc($request->password);
}
$this->vCenterRepository->update($id, $data);
DB::commit();
@@ -127,11 +131,11 @@ class ModulevCenterController extends Controller
}
return redirect()->route('module.vcenter.index')->with('success', 'Updated Successfully');
}
public function destroy(int $id = 0)
{
$server = $this->vCenterRepository->find($id);
if (! $server) {
if (!$server) {
return back()->withErrors('Invalid Request');
}
DB::beginTransaction();
@@ -145,4 +149,36 @@ class ModulevCenterController extends Controller
}
return redirect()->route('module.vcenter.index')->with('success', 'Deleted successfully.');
}
public function datatable(Request $request)
{
$query = $this->vCenterRepository->filter(
$request->all(),
[],
[],
['*'],
true
);
return DataTables::eloquent($query)
->addColumn(
'action',
function ($d) {
return view('administrator.pages.module.vcenter.datatable.action', ['row' => $d])->render();
}
)
->addColumn(
'status',
function ($d) {
return view('administrator.pages.module.vcenter.datatable.status', ['row' => $d])->render();
}
)
->filterColumn('v_center.host', function ($query, $keyword) {
$query->whereHas('vCenter', function ($q) use ($keyword) {
$q->where('host', 'like', "%{$keyword}%");
});
})
->rawColumns(['action', 'status'])
->make(true);
}
}