pendingAttachments = $data['attachments'] ?? []; $this->pendingCollection = $data['attachment_collection'] ?? 'general'; unset($data['is_general'], $data['attachment_collection'], $data['attachments']); return $data; } protected function afterCreate(): void { $feedback = $this->getRecord(); $feedback->interactions()->create([ 'user_id' => auth()->id(), 'type' => 'note', 'content' => __('feedback.created_via', ['channel' => $feedback->feedbackChannel?->name ?? __('feedback.unknown_channel')]), 'changes' => ['status' => ['old' => null, 'new' => $feedback->status]], ]); if (empty($this->pendingAttachments)) { return; } $disk = Storage::disk('public'); foreach ($this->pendingAttachments as $path) { if (! $disk->exists($path)) { continue; } if ($feedback->attachments()->where('path', $path)->exists()) { continue; } $feedback->attachments()->create([ 'uuid' => (string) \Illuminate\Support\Str::uuid(), 'user_id' => auth()->id(), 'name' => basename($path), 'path' => $path, 'disk' => 'public', 'collection' => $this->pendingCollection, 'mime_type' => $this->safeMimeType($disk, $path), 'size' => $this->safeFileSize($disk, $path), ]); } } protected function safeMimeType($disk, string $path): ?string { try { return $disk->mimeType($path); } catch (\Exception $e) { return null; } } protected function safeFileSize($disk, string $path): ?int { try { return $disk->size($path); } catch (\Exception $e) { return null; } } }