[13.x] Populate mailable recipients in mail notifications#60259
Draft
LucasCavalheri wants to merge 1 commit into
Draft
[13.x] Populate mailable recipients in mail notifications#60259LucasCavalheri wants to merge 1 commit into
LucasCavalheri wants to merge 1 commit into
Conversation
When a notification returns a Mailable without recipients, use the notifiable's mail route—the same behavior as MailMessage notifications.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a notification
toMail()method returns aMailableinstance without recipients, theMailChannelcurrently sends the message without automatically using the notifiable mail route.This differs from the existing
MailMessagebehavior, where recipients are automatically resolved from the notifiable.This PR aligns both behaviors by automatically populating recipients for
Mailablenotifications only when no recipients were explicitly defined.Changes
Populate recipients from the notifiable mail route when:
Mailablehas notorecipientsMailableenvelope()does not define recipientsPreserve existing behavior when:
->to()envelope()->toRemove the unused
$messageparameter fromgetRecipients()Motivation
MailMessagenotifications already resolve recipients automatically from the notifiable.Returning a
MailablefromtoMail()should behave consistently and avoid requiring users to manually duplicate recipient resolution logic for the most common notification flow.This also improves developer experience and reduces subtle delivery mistakes when converting notifications from
MailMessagetoMailable.Backward Compatibility
This change is fully backward compatible.
Existing applications that already define recipients explicitly on the
Mailableare unaffected because the channel only populates recipients when none are present.Tests
Added
tests/Notifications/MailChannelTest.phpcovering:->to()envelope()->torouteNotificationForMail()Additional integration coverage was added to
SendingNotificationsWithLocaleTest.php.