Update source into github
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\admin\package;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Package\OsVersionRequest;
|
||||
use App\Models\ModuleDatacenter;
|
||||
use App\Models\ModuleDatastore;
|
||||
use App\Models\ModuleHost;
|
||||
use App\Models\Os;
|
||||
use App\Models\OsGroup;
|
||||
use App\Models\vCenter;
|
||||
use App\Http\Services\vCenter as ServiceVCenter;
|
||||
use App\Repositories\Os\OsRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class OsVersion extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public OsRepositoryInterface $osRepository
|
||||
) {}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$versions = $this->osRepository->filter([
|
||||
'page' => $request->get('page') ?? 1
|
||||
], ['osGroup.host']);
|
||||
$title = 'List all Version OS';
|
||||
|
||||
return view('admin.package.version.index', compact('versions', 'title'));
|
||||
}
|
||||
public function create()
|
||||
{
|
||||
$title = 'Add new Version Os';
|
||||
|
||||
return view('admin.package.version.add', compact('title'));
|
||||
}
|
||||
public function store(OsVersionRequest $request)
|
||||
{
|
||||
$request->validated();
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$this->osRepository->create($request->all());
|
||||
DB::commit();
|
||||
} catch (\Exception $error) {
|
||||
DB::rollBack();
|
||||
return back()->withErrors($error->getMessage());
|
||||
}
|
||||
return redirect()->route('package.version.index')->with('success', 'Add Os Version successfully');
|
||||
}
|
||||
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('admin.package.version.edit', compact('title', 'version'));
|
||||
}
|
||||
public function update(int $id = 0, OsVersionRequest $request)
|
||||
{
|
||||
$version = $this->osRepository->find($id);
|
||||
if (! $version) {
|
||||
return back()->withErrors('Can\'t find version os by ID #' . $id);
|
||||
}
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$this->osRepository->update($id,$request->all());
|
||||
DB::commit();
|
||||
} catch (\Exception $error) {
|
||||
DB::rollBack();
|
||||
return back()->withErrors($error->getMessage());
|
||||
}
|
||||
return redirect()->route('package.version.index')->with('success', 'Update successfully');
|
||||
}
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'oid' => 'numeric'
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator->getMessageBag());
|
||||
}
|
||||
|
||||
$version = Os::find($request->oid);
|
||||
if (! $version) {
|
||||
return back()->withErrors('Can\'t find version os by ID #' . $request->oid);
|
||||
}
|
||||
$version->delete();
|
||||
|
||||
return back()->with('success', 'Delete success');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user