update logic call

This commit is contained in:
pbao9
2026-01-31 10:08:25 +07:00
parent 72b690f22e
commit 669ed87a05
144 changed files with 600 additions and 12093 deletions
@@ -11,13 +11,15 @@ use App\Repositories\Module\Host\HostRepositoryInterface;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Yajra\DataTables\Facades\DataTables;
class Datastore extends Controller
{
public function __construct(
public DatastoreRepositoryInterface $datastoreRepository,
public HostRepositoryInterface $hostRepository
) {}
) {
}
//
public function index(Request $request)
{
@@ -30,7 +32,7 @@ class Datastore extends Controller
]
);
$title = 'List all datastore';
return view('admin.package.datastore.index', compact('title', 'datastore'));
return view('administrator.pages.package.datastore.index', compact('title', 'datastore'));
}
public function sync(SyncDatastore $syncDatastore)
{
@@ -41,14 +43,14 @@ class Datastore extends Controller
public function create()
{
$title = 'Add Datastore';
return view('admin.package.datastore.add', compact('title'));
return view('administrator.pages.package.datastore.add', compact('title'));
}
public function store(DatastoreRequest $request)
{
$request->validated();
$host = $this->hostRepository->find($request->get('module_host_id'));
if (! $host) {
if (!$host) {
return back()->withErrors('Invalid Request');
}
$isCreated = $this->datastoreRepository->findBy('datastore', $request->get('datastore'));
@@ -70,23 +72,23 @@ class Datastore extends Controller
{
$datastore = $this->datastoreRepository->findWithRelationships($id, ['host.datacenter']);
if (! $datastore) {
if (!$datastore) {
return back()->withErrors('Invalid Request');
}
$title = 'Edit Datastore';
return view('admin.package.datastore.edit', compact('title', 'datastore'));
return view('administrator.pages.package.datastore.edit', compact('title', 'datastore'));
}
public function update(int $id, DatastoreRequest $request)
{
$datastore = $this->datastoreRepository->find($id);
if (! $datastore) {
if (!$datastore) {
return redirect()->route('package.datastore.index')->withErrors('Invalid request.');
}
$request->validated();
$host = $this->hostRepository->find($request->get('module_host_id'));
if (! $host) {
if (!$host) {
return back()->withErrors('Invalid Request');
}
if ($request->get('datastore') !== $datastore->datastore) {
@@ -110,7 +112,7 @@ class Datastore extends Controller
{
$datastore = $this->datastoreRepository->find($id);
if (! $datastore) {
if (!$datastore) {
return back()->withErrors('Invalid request.');
}
@@ -124,4 +126,28 @@ class Datastore extends Controller
}
return redirect()->route('package.datastore.index')->with('success', 'Deleted datacenter successfully!');
}
public function datatable(Request $request)
{
$query = $this->datastoreRepository->filter(
$request->all(),
['host.datacenter.vCenter'],
[],
['*'],
true
);
return DataTables::eloquent($query)
->addColumn(
'action',
fn($d) =>
'<a href="' . route('package.datastore.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);
}
}