Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MailcoachMessage class for use in notification classes #19

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

gdebrauwer
Copy link
Contributor

When you want to sent a mail using mailcoach from within a notification class, you have to create a mailable class and call that class from within your notification

class FooNotification extends Notification
{
    public function via()
    {
        return ['mail'];
    }

    public function toMail()
    {
        return new FooMail();
    }
}

Having to create a mailable class is a bit annoying. This PR fixes that by allowing you to return a mailcoach message right from within your notification classs.

class FooNotification extends Notification
{
    public function via()
    {
        return ['mail'];
    }

    public function toMail()
    {
        return (new MailcoachMessage())
			->usingMail('mail-template-name')
			->replacing('some-key', 'some-value');
    }
}

@freekmurze
Copy link
Member

Might be good to add an example of this in the readme as well.

@Nielsvanpach
Copy link
Member

Thanks for your work on this!

@Nielsvanpach Nielsvanpach merged commit c995644 into spatie:main Oct 7, 2024
1 check passed
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.

3 participants