Skip to content

[13.x] Add BackedEnum support to SimpleMessage mailer method#59680

Closed
julesjanssen wants to merge 1 commit into
laravel:13.xfrom
julesjanssen:13.x
Closed

[13.x] Add BackedEnum support to SimpleMessage mailer method#59680
julesjanssen wants to merge 1 commit into
laravel:13.xfrom
julesjanssen:13.x

Conversation

@julesjanssen

@julesjanssen julesjanssen commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Adds Enum support to the mailer() method on Illuminate\Notifications\Messages\SimpleMessage (and therefore MailMessage), matching the behavior already present in Illuminate\Mail\MailManager::mailer().

This allows a dedicated mailer to be selected using an enum when composing a mail notification, instead of a hard-coded string:

enum Mailer: string
{
    case Postmark = 'postmark';
    case Ses = 'ses';
}

public function toMail(object $notifiable): MailMessage
{
    return (new MailMessage)                                                                                                                                                
        ->mailer(Mailer::Postmark)
        ->subject('Welcome')
        ->line('Thanks for signing up!');
}

Plain strings continue to work as before — the value is resolved through the enum_value() helper.

@jackbayliss

Copy link
Copy Markdown
Contributor

If this is to match MailManager::mailer, shouldnt it be UnitEnum? 👀

@julesjanssen

Copy link
Copy Markdown
Contributor Author

Hmm. You're right, but how is that even useful?
How / why would I use this method with a non-backed Enum?

@shaedrich

Copy link
Copy Markdown
Contributor

enum_value() returns

  • BackedEnum::$value
  • UnitEnum::$name
  • the string value passed directly

@julesjanssen

Copy link
Copy Markdown
Contributor Author

Makes sense. Thank you.
I updated the PR.

@taylorotwell

Copy link
Copy Markdown
Member

I've got Enum PR fatigue.

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.

4 participants