Update to laravel 12, other changes.
This commit is contained in:
@@ -21,4 +21,31 @@ public function index(Request $request){
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function updateAction(int $id, Request $request) {
|
||||
|
||||
$row = \App\Models\Action::findOrFail($id);
|
||||
|
||||
$attributes = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'color_tag' => 'nullable|string|max:25',
|
||||
'decisions' => 'nullable|array',
|
||||
'decisions.*.id' => 'required_with:decisions.*|integer|exists:decisions,id',
|
||||
'decisions.*.name' => 'required_with:decisions.*|string|max:50'
|
||||
]);
|
||||
|
||||
$decisionIds = collect($attributes['decisions'] ?? [])->pluck('id')->toArray();
|
||||
|
||||
\DB::transaction(function() use ($attributes, $decisionIds, $row) {
|
||||
$row->update([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag']
|
||||
]);
|
||||
|
||||
$row->decisions()->sync($decisionIds);
|
||||
});
|
||||
logger()->info('Model updated successfully', ['model_id' => $row->id]);
|
||||
return to_route('settings')->with('success', 'Update successful!');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user