2021-04-07 00:25:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\PortGroup;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
use Toastr;
|
|
|
|
|
|
|
|
class PortGroupController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2021-04-20 12:47:22 +02:00
|
|
|
* @return \Illuminate\View\View
|
2021-04-07 00:25:08 +02:00
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return view('port-group.index', [
|
2021-08-24 02:06:36 +02:00
|
|
|
'port_groups' => PortGroup::orderBy('name')->withCount('ports')->get(),
|
2021-04-07 00:25:08 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2021-04-20 12:47:22 +02:00
|
|
|
* @return \Illuminate\View\View
|
2021-04-07 00:25:08 +02:00
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
return view('port-group.create', [
|
|
|
|
'port_group' => new PortGroup(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2021-04-20 12:47:22 +02:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2021-04-07 00:25:08 +02:00
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'name' => 'required|string|unique:port_groups',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$portGroup = PortGroup::make($request->only(['name', 'desc']));
|
|
|
|
$portGroup->save();
|
|
|
|
|
|
|
|
Toastr::success(__('Port Group :name created', ['name' => $portGroup->name]));
|
|
|
|
|
|
|
|
return redirect()->route('port-groups.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\PortGroup $portGroup
|
2021-04-20 12:47:22 +02:00
|
|
|
* @return \Illuminate\View\View
|
2021-04-07 00:25:08 +02:00
|
|
|
*/
|
|
|
|
public function edit(PortGroup $portGroup)
|
|
|
|
{
|
|
|
|
return view('port-group.edit', [
|
|
|
|
'port_group' => $portGroup,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \App\Models\PortGroup $portGroup
|
2021-04-20 12:47:22 +02:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2021-04-07 00:25:08 +02:00
|
|
|
*/
|
|
|
|
public function update(Request $request, PortGroup $portGroup)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'name' => [
|
|
|
|
'required',
|
|
|
|
'string',
|
|
|
|
'max:255',
|
|
|
|
Rule::unique('port_groups', 'name')->where(function ($query) use ($portGroup) {
|
|
|
|
$query->where('id', '!=', $portGroup->id);
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
'desc' => 'string|max:255',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$portGroup->fill($request->only(['name', 'desc']));
|
|
|
|
|
|
|
|
if ($portGroup->save()) {
|
|
|
|
Toastr::success(__('Port Group :name updated', ['name' => $portGroup->name]));
|
|
|
|
} else {
|
|
|
|
Toastr::error(__('Failed to save'));
|
|
|
|
|
|
|
|
return redirect()->back()->withInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('port-groups.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\PortGroup $portGroup
|
2021-04-07 00:25:08 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy(PortGroup $portGroup)
|
|
|
|
{
|
|
|
|
$portGroup->delete();
|
|
|
|
|
|
|
|
$msg = __('Port Group :name deleted', ['name' => $portGroup->name]);
|
|
|
|
|
|
|
|
return response($msg, 200);
|
|
|
|
}
|
|
|
|
}
|