Accept attachments on ticket create
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user