Skip to content

[13.x] Add attachFromStorage helpers to notification MailMessage#60268

Open
LucasCavalheri wants to merge 1 commit into
laravel:13.xfrom
LucasCavalheri:feat/mail-message-storage-attachments
Open

[13.x] Add attachFromStorage helpers to notification MailMessage#60268
LucasCavalheri wants to merge 1 commit into
laravel:13.xfrom
LucasCavalheri:feat/mail-message-storage-attachments

Conversation

@LucasCavalheri
Copy link
Copy Markdown
Contributor

Summary

This PR adds attachFromStorage and attachFromStorageDisk helpers to notification MailMessage.

These methods mirror the storage attachment API available on mailables and delegate to Attachment::fromStorageDisk() before attaching the generated attachment to the message.

Motivation

After #58201, mailables support attaching files directly from storage using dedicated helpers.

Notification mail messages can already attach Attachment instances, but they do not provide the same convenience methods for storage-backed attachments. This creates a small API inconsistency between Mailable and notification MailMessage.

Adding these helpers improves parity and makes notification mail attachments more ergonomic.

Changes

  • Added attachFromStorage() to MailMessage
  • Added attachFromStorageDisk() to MailMessage
  • Delegates storage attachment creation to Attachment::fromStorageDisk()
  • Applies custom attachment name and MIME options when provided
  • Added test coverage for local and disk-specific storage attachments

Example

MailMessage::make()
    ->attachFromStorage('invoices/1.pdf')
    ->attachFromStorageDisk('s3', 'invoices/1.pdf', 'invoice.pdf', [
        'mime' => 'application/pdf',
    ]);

Tests

Added coverage in NotificationMailMessageTest:

  • testItAttachesFilesFromStorage
  • testItAttachesFilesFromStorageDisk

Verified with:

./vendor/bin/phpunit tests/Notifications/NotificationMailMessageTest.php
./vendor/bin/pint

Backward Compatibility

This change is fully backward compatible.

It only adds new convenience methods to notification MailMessage and does not alter existing attachment behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant