diff --git a/src/Http/Controllers/TicketController.php b/src/Http/Controllers/TicketController.php index a66b04c..0689180 100644 --- a/src/Http/Controllers/TicketController.php +++ b/src/Http/Controllers/TicketController.php @@ -266,9 +266,11 @@ class TicketController extends Controller 'group_id' => 'required|exists:ticketing_groups,id', 'priority_id' => 'nullable|exists:ticketing_priority_levels,id', 'due_date' => 'nullable|date', + 'attachments' => 'nullable|array|max:5', + 'attachments.*' => 'file|max:20480', ]); - // Bug #4: Ensure priority belongs to the chosen group (or is global) + // Ensure priority belongs to the chosen group (or is global) if (!empty($validated['priority_id'])) { $priority = PriorityLevel::find($validated['priority_id']); if ($priority && $priority->group_id !== null && $priority->group_id != $validated['group_id']) { @@ -280,12 +282,28 @@ class TicketController extends Controller $number = $group->nextTicketNumber(); $ticket = Ticket::create([ - ...$validated, + ...collect($validated)->except('attachments')->all(), 'number' => $number, 'submitter_id' => Auth::id(), 'status' => 'open', ]); + if ($request->hasFile('attachments')) { + $disk = config('ticketing.storage_disk', env('TICKETING_STORAGE_DISK', 'local')); + foreach ($request->file('attachments') as $file) { + if (!$file->isValid()) continue; + $path = $file->store('ticketing/attachments/' . $ticket->id, $disk); + \Dashboard\Ticketing\Models\TicketAttachment::create([ + 'ticket_id' => $ticket->id, + 'message_id' => null, + 'filename' => $file->getClientOriginalName(), + 'path' => $path, + 'mime_type' => $file->getMimeType(), + 'size' => $file->getSize(), + ]); + } + } + return redirect()->route('ticketing.show', $ticket); }