'boolean', ]; public function message(): BelongsTo { return $this->belongsTo(EmailMessage::class, 'email_message_id'); } public function documento(): BelongsTo { return $this->belongsTo(Documento::class, 'documenti_id'); } public function getUrlAttribute(): string { return route('email.attachment.download', $this->id); } public function saveToDocumenti(): ?Documento { if ($this->is_saved_to_documenti || !$this->documenti_id) { return $this->documento; } $documento = Documento::create([ 'nome_file' => $this->filename, 'file_path' => $this->file_path, 'tipo' => 'upload', 'tipologia' => 'email_attachment', 'mime_type' => $this->mime_type, 'dimensione' => $this->size, 'note' => 'Allegato email: ' . ($this->message->subject ?? ''), ]); $this->update(['is_saved_to_documenti' => true, 'documenti_id' => $documento->id]); return $documento; } public function getIconAttribute(): string { if (str_starts_with($this->mime_type, 'image/')) { return 'fa-image'; } if (str_starts_with($this->mime_type, 'video/')) { return 'fa-video'; } if (str_starts_with($this->mime_type, 'audio/')) { return 'fa-music'; } if (str_contains($this->mime_type, 'pdf')) { return 'fa-file-pdf'; } if (str_contains($this->mime_type, 'word')) { return 'fa-file-word'; } if (str_contains($this->mime_type, 'excel') || str_contains($this->mime_type, 'spreadsheet')) { return 'fa-file-excel'; } return 'fa-file'; } }