© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
TheNastyPasty

Attach file with original name to mail throws exception

Hello,

I am trying for hours now to attach files to a mail, but without success. I am using the filament 3
->storeFileNamesIn('attachment_names')
->storeFileNamesIn('attachment_names')
function.

Code which works
$attachments = [];

  foreach ($this->template->attachments as $attachment) {
      $attachments[] = Attachment::fromStorageDisk('local', $attachment);
  }
  
  return $attachments;
$attachments = [];

  foreach ($this->template->attachments as $attachment) {
      $attachments[] = Attachment::fromStorageDisk('local', $attachment);
  }
  
  return $attachments;

But I want to add the stored file names and that does not work. I get the following exception
Symfony\Component\Mime\Email::attachFromPath(): Argument #1 ($path) must be of type string, App\Mail\UserTemplate given
Symfony\Component\Mime\Email::attachFromPath(): Argument #1 ($path) must be of type string, App\Mail\UserTemplate given


public function attachments(): array
  {
      $attachments = [];
      $attachment_names = $this->template->attachment_names;

      foreach ($this->template->attachments as $attachment) {
          $value = $attachment_names[$attachment] ?? null;
          $attachments[] = $this->attachFromStorageDisk('local', $attachment, $value);
      }

      return $attachments;
  }
public function attachments(): array
  {
      $attachments = [];
      $attachment_names = $this->template->attachment_names;

      foreach ($this->template->attachments as $attachment) {
          $value = $attachment_names[$attachment] ?? null;
          $attachments[] = $this->attachFromStorageDisk('local', $attachment, $value);
      }

      return $attachments;
  }

Please someone can help

Maybe there is a better way to attach files in filament 3 I dont know of.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

FileUpload file saved with encrypted name, preview with original name
FilamentFFilament / ❓┊help
3y ago
SpatieMediaLibraryFileUpload: Display original file name
FilamentFFilament / ❓┊help
3y ago
How to download a file from FileUpload with original name
FilamentFFilament / ❓┊help
13mo ago
storeFileNamesIn not able to use original file name as label?
FilamentFFilament / ❓┊help
3y ago