mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Add validation
This commit is contained in:
parent
53c084c6c0
commit
79d1147f20
|
@ -6,24 +6,32 @@ use App\Events\NoteAdded;
|
|||
use App\Models\Asset;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class NotesController extends Controller
|
||||
{
|
||||
public function store(Request $request)
|
||||
{
|
||||
// @todo: validation
|
||||
$validated = $request->validate([
|
||||
// @todo: improve?
|
||||
'id' => 'required',
|
||||
'note' => 'required|string|max:500',
|
||||
'type' => [
|
||||
'required',
|
||||
Rule::in(['asset']),
|
||||
],
|
||||
]);
|
||||
|
||||
$item = Asset::findOrFail($request->input('id'));
|
||||
$item = Asset::findOrFail($validated['id']);
|
||||
|
||||
// @todo: authorization
|
||||
|
||||
event(new NoteAdded($item, Auth::user(), $request->input('note')));
|
||||
event(new NoteAdded($item, Auth::user(), $validated['note']));
|
||||
|
||||
return redirect()
|
||||
// @todo: make dynamic
|
||||
->route('hardware.show', $request->input('id'))
|
||||
->route('hardware.show', $validated['id'])
|
||||
->withFragment('history')
|
||||
// @todo: translate
|
||||
->with('success', 'Success!');
|
||||
->with('success', 'Note Added!');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue