2025-02-18 15:20:06 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2025-02-18 16:04:53 -08:00
|
|
|
use App\Models\Actionlog;
|
2025-02-18 15:43:58 -08:00
|
|
|
use App\Models\Asset;
|
2025-02-18 15:20:06 -08:00
|
|
|
use Illuminate\Http\Request;
|
2025-02-18 15:43:58 -08:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2025-02-18 15:46:52 -08:00
|
|
|
use Illuminate\Validation\Rule;
|
2025-02-18 15:20:06 -08:00
|
|
|
|
|
|
|
class NotesController extends Controller
|
|
|
|
{
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2025-02-20 12:51:08 -08:00
|
|
|
$this->authorize('update', Asset::class);
|
|
|
|
|
2025-02-18 15:46:52 -08:00
|
|
|
$validated = $request->validate([
|
|
|
|
'id' => 'required',
|
2025-02-22 04:56:25 -08:00
|
|
|
'note' => 'required|string|max:50000',
|
2025-02-18 15:46:52 -08:00
|
|
|
'type' => [
|
|
|
|
'required',
|
|
|
|
Rule::in(['asset']),
|
|
|
|
],
|
|
|
|
]);
|
2025-02-18 15:43:58 -08:00
|
|
|
|
2025-02-18 15:46:52 -08:00
|
|
|
$item = Asset::findOrFail($validated['id']);
|
2025-02-18 15:43:58 -08:00
|
|
|
|
2025-02-18 16:24:52 -08:00
|
|
|
$this->authorize('update', $item);
|
2025-02-18 15:43:58 -08:00
|
|
|
|
2025-02-20 12:41:56 -08:00
|
|
|
$logaction = new Actionlog;
|
2025-02-18 16:04:53 -08:00
|
|
|
$logaction->item_id = $item->id;
|
|
|
|
$logaction->item_type = get_class($item);
|
|
|
|
$logaction->note = $validated['note'];
|
|
|
|
$logaction->created_by = Auth::id();
|
|
|
|
$logaction->logaction('note added');
|
2025-02-18 15:43:58 -08:00
|
|
|
|
|
|
|
return redirect()
|
2025-02-18 15:46:52 -08:00
|
|
|
->route('hardware.show', $validated['id'])
|
2025-02-18 15:43:58 -08:00
|
|
|
->withFragment('history')
|
2025-02-20 12:41:56 -08:00
|
|
|
->with('success', trans('general.note_added'));
|
2025-02-18 15:20:06 -08:00
|
|
|
}
|
|
|
|
}
|