snipe-it/app/Http/Controllers/SavedReportsController.php

45 lines
1.1 KiB
PHP
Raw Normal View History

2023-08-28 16:26:31 -07:00
<?php
namespace App\Http\Controllers;
2023-12-11 16:20:36 -08:00
use App\Models\SavedReport;
2023-08-28 16:26:31 -07:00
use Illuminate\Http\Request;
class SavedReportsController extends Controller
{
public function store(Request $request)
{
$this->authorize('reports.view');
2023-12-11 16:20:36 -08:00
$request->validate((new SavedReport)->getRules());
2023-12-11 14:19:03 -08:00
$report = $request->user()->savedReports()->create([
2023-12-11 16:20:36 -08:00
'name' => $request->get('name'),
'options' => $request->except(['_token', 'name']),
2023-12-11 14:19:03 -08:00
]);
2023-12-11 14:19:03 -08:00
return redirect()->route('reports/custom', ['report' => $report->id]);
2023-08-28 16:26:31 -07:00
}
2023-12-13 14:31:58 -08:00
public function update(Request $request)
{
$this->authorize('update',SavedReport::class);
if(is_null($reportid = SavedReport::find($request)))
{
return redirect()->route('reports/custom');
}
$request->validate()->report->id->getRules();
$report = $request->user()->savedReports()->edit([
'name' => $request->get('name'),
'options' => $request->except(['token','name']),
]);
return redirect()->route('reports/custom', ['report' => $report->id]);
}
2023-08-28 16:26:31 -07:00
}