Files
librenms-librenms/app/Http/Controllers/InventoryController.php
Tony Murray 5c25cece48 Convert the inventory page to Laravel (#15004)
* Convert the inventory page to Laravel
Fix several XSS issues (hopefully no new ones snuck in)
Small improvement to the SelectController to allow filtering by filterFields()

* style fixes

* Fix lint issues

* Fix part device filter
2023-04-28 07:51:41 -05:00

51 lines
1.5 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\EntPhysical;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
class InventoryController extends Controller
{
public function __invoke(Request $request): View
{
$this->validate($request, [
'device' => 'nullable|int',
'descr' => 'nullable|string',
'model' => 'nullable|string',
'serial' => 'nullable|string',
]);
$device = \App\Models\Device::hasAccess($request->user())
->select(['device_id', 'hostname', 'ip', 'sysName', 'display'])
->firstWhere('device_id', $request->get('device'));
$model_filter = ['field' => 'model'];
$device_selected = '';
if ($device) {
$device_selected = ['id' => $device->device_id, 'text' => $device->displayName()];
$model_filter['device_id'] = $device->device_id;
}
return view('inventory', [
'device_selected' => $device_selected,
'filter' => [
'device' => $device?->device_id,
'descr' => $request->get('descr'),
'model' => $request->get('model'),
'serial' => $request->get('serial'),
],
'model_filter' => $model_filter,
'show_purge' => EntPhysical::whereDoesntHave('device')->exists(),
]);
}
public function purge()
{
EntPhysical::whereDoesntHave('device')->delete();
return redirect()->back();
}
}