validate([ 'company_id' => ['nullable', 'integer'], 'subject' => ['required', 'string', 'max:200'], 'body' => ['required', 'string', 'min:10'], 'priority_id' => ['required', 'integer', Rule::exists('helpdesk_priorities', 'id')], 'category_id' => ['nullable', 'integer', Rule::exists('helpdesk_categories', 'id')], 'project_id' => ['nullable', 'integer', Rule::exists('helpdesk_projects', 'id')], 'team_id' => ['nullable', 'integer', Rule::exists('helpdesk_teams', 'id')], 'due_at' => ['nullable', 'date'], 'attachments' => ['nullable', 'array'], 'attachments.*' => ['file', 'max:' . $maxUploadKilobytes, 'mimes:' . implode(',', $allowedMimes)], ]); $user = Auth::user(); abort_if($user === null, 403); $uploadedFiles = $request->file('attachments', []); $uploadedFiles = is_array($uploadedFiles) ? $uploadedFiles : [$uploadedFiles]; $ticket = $tickets->create($user, [ 'company_id' => $validated['company_id'] ?? null, 'subject' => $validated['subject'], 'body' => $validated['body'], 'priority_id' => $validated['priority_id'], 'category_id' => $validated['category_id'] ?? null, 'project_id' => $validated['project_id'] ?? null, 'team_id' => $validated['team_id'] ?? null, 'due_at' => $validated['due_at'] ?? null, ], $uploadedFiles); return redirect() ->route('helpdesk.tickets.index') ->with('success', 'Ticket ' . $ticket->reference . ' has been created.'); } }