mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* PHP-Flasher for toast messages Allows customized template removes dependency on unmaintained package using dev stability no solution for javascript toasts yet Use DI in places it makes sense allow html in flashes Use "template.librenms" as a default notification style merge toast containers toastr needs to be second because it will find the containr made by flasher, but the inverse is not true upgrade php-flasher to add custom options and persistent notifications Add dark theme * update composer.lock
118 lines
3.1 KiB
PHP
118 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\PortGroup;
|
|
use Flasher\Prime\FlasherInterface;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class PortGroupController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\View\View
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('port-group.index', [
|
|
'port_groups' => PortGroup::orderBy('name')->withCount('ports')->get(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\View\View
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('port-group.create', [
|
|
'port_group' => new PortGroup(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function store(Request $request, FlasherInterface $flasher)
|
|
{
|
|
$this->validate($request, [
|
|
'name' => 'required|string|unique:port_groups',
|
|
]);
|
|
|
|
$portGroup = PortGroup::make($request->only(['name', 'desc']));
|
|
$portGroup->save();
|
|
|
|
$flasher->addSuccess(__('Port Group :name created', ['name' => $portGroup->name]));
|
|
|
|
return redirect()->route('port-groups.index');
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Models\PortGroup $portGroup
|
|
* @return \Illuminate\View\View
|
|
*/
|
|
public function edit(PortGroup $portGroup)
|
|
{
|
|
return view('port-group.edit', [
|
|
'port_group' => $portGroup,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \App\Models\PortGroup $portGroup
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update(Request $request, PortGroup $portGroup, FlasherInterface $flasher)
|
|
{
|
|
$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()) {
|
|
$flasher->addSuccess(__('Port Group :name updated', ['name' => $portGroup->name]));
|
|
} else {
|
|
$flasher->addError(__('Failed to save'));
|
|
|
|
return redirect()->back()->withInput();
|
|
}
|
|
|
|
return redirect()->route('port-groups.index');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Models\PortGroup $portGroup
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(PortGroup $portGroup)
|
|
{
|
|
$portGroup->delete();
|
|
|
|
$msg = __('Port Group :name deleted', ['name' => $portGroup->name]);
|
|
|
|
return response($msg, 200);
|
|
}
|
|
}
|