This commit is contained in:
pbao9
2026-02-02 10:06:42 +07:00
parent a2a75b2015
commit 34575b2d96
29 changed files with 253 additions and 157 deletions
@@ -15,6 +15,7 @@ use App\Repositories\Os\OsRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Yajra\DataTables\Facades\DataTables;
class OsVersion extends Controller
{
@@ -39,10 +40,10 @@ class OsVersion extends Controller
public function store(OsVersionRequest $request)
{
$validatedData = $request->validated();
// Remove unnecessary fields
unset($validatedData['vcenter_id'], $validatedData['module_datacenter_id']);
DB::beginTransaction();
try {
$this->osRepository->create($validatedData);
@@ -55,14 +56,11 @@ class OsVersion extends Controller
}
public function edit(int $id = 0)
{
$version = $this->osRepository->findWithRelationships($id, ['osGroup.host.datacenter.vCenter']);
if (! $version) {
return back()->withErrors('Can\'t find version os by ID #' . $id);
}
$title = "Edit version OS";
return view('administrator.pages.package.version.edit', compact('title', 'version'));
@@ -73,12 +71,12 @@ class OsVersion extends Controller
if (! $version) {
return back()->withErrors('Can\'t find version os by ID #' . $id);
}
$validatedData = $request->validated();
// Remove unnecessary fields
unset($validatedData['vcenter_id'], $validatedData['module_datacenter_id']);
DB::beginTransaction();
try {
$this->osRepository->update($id, $validatedData);
@@ -106,4 +104,36 @@ class OsVersion extends Controller
return back()->with('success', 'Delete success');
}
public function datatable(Request $request)
{
$query = $this->osRepository->filter(
[],
['osGroup'],
[],
['*'],
true
);
return DataTables::eloquent($query)
->editColumn('os_group', function ($d) {
return $d->osGroup ? $d->osGroup->name . ' - ' . $d->osGroup->host->name : '';
})
->editColumn('status', function ($d) {
return $d->getStatus();
})
->addColumn('action', function ($d) {
return '<a href="' . route('package.version.edit', $d->id) . '"
class="btn btn-primary btn-sm">
Edit
</a>';
})
->filterColumn('host', function ($query, $keyword) {
$query->whereHas('host', function ($q) use ($keyword) {
$q->where('host', 'like', "%{$keyword}%");
});
})
->rawColumns(['action', 'status'])
->make(true);
}
}