Skip to content

[5.8] Add template theme to mail notifications#29132

Merged
taylorotwell merged 2 commits into
laravel:5.8from
troccoli:add-template-theme-to-mail-notifications
Jul 11, 2019
Merged

[5.8] Add template theme to mail notifications#29132
taylorotwell merged 2 commits into
laravel:5.8from
troccoli:add-template-theme-to-mail-notifications

Conversation

@troccoli

Copy link
Copy Markdown
Contributor

It is already possible, and quite easily, to set a theme for any Mailables. This is not the case for the mail Notifications, which always use the default theme.

With this PR it would be possible to do something like

public function toMail($notifiable)
{
  $url = url('/invoice/'.$this->invoice->id);

  return (new MailMessage)
      ->theme('notification')
      ->greeting('Hello!')
      ->line('One of your invoices has been paid!')
      ->action('View Invoice', $url)
      ->line('Thank you for using our application!');
}

This will use notification.css theme in resources/views/vendor/mail/html/themes.

@troccoli troccoli changed the title Add template theme to mail notifications [5.8] Add template theme to mail notifications Jul 10, 2019
We already can set a different theme than the default one for our
Mailable. It would be very useful if there was a way to set the theme
for the mail notifications too.
@taylorotwell taylorotwell merged commit 2e96129 into laravel:5.8 Jul 11, 2019
@troccoli

Copy link
Copy Markdown
Contributor Author

Would there be any interest in backporting this to 5.7?

We are using 5.7 here and it would be useful for us.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

Laravel 5.7 is not accepting new features now, since it is EOL. Only security fixes. Please upgrade to Laravel 5.8.

@martinbean

Copy link
Copy Markdown
Contributor

Please upgrade to Laravel 5.8.

@GrahamCampbell Upgrading a framework is easier said that done for some teams and products. Especially if 5.7 to 5.8 is a major framework upgrade as defined here: https://laravel.com/docs/5.8/releases#versioning-scheme

@driesvints

Copy link
Copy Markdown
Member

@martinbean Laravel Shift can help you: https://laravelshift.com/

@martinbean

Copy link
Copy Markdown
Contributor

@driesvints I’m not having issues upgrading…?

I was just empathising with @troccoli and trying to convey to @GrahamCampbell that not every developer is able to perform an upgrade to a major framework version every ~6 months, i.e. if a developer is working for a company with limited resources.

@driesvints

Copy link
Copy Markdown
Member

@martinbean you said:

Upgrading a framework is easier said that done for some teams and products.

So I was just pointing out to a tool that could help you upgrade faster/easier.

@martinbean

Copy link
Copy Markdown
Contributor

@driesvints Again, it’s not me in that situation, but have worked in product teams in the past where shipping features is a higher priority for teams than keeping package versions up to date.

@driesvints

Copy link
Copy Markdown
Member

@martinbean I don't want to get into a "priority" discussion here. I've worked in teams before where upgrading isn't always a top priority. But you're gonna be left behind and run into security risks/bugs eventually if you do. Expecting others to keep maintaining old versions if you're not willing to upgrade is kind of demanding if you ask me.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

LTS releases are also available. For example, StyleCI is actually running on Laravel 5.5 LTS. This is so I don't have to spent lots of time upgrading every few months.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

Features are very rarely backported however. If you need new features from the core, then upgrading is the only way.

@DevDavido

Copy link
Copy Markdown

Nice idea, definitely like it! It would be great though to get it documented in the docs.

@troccoli

Copy link
Copy Markdown
Contributor Author

Absolutely @DevDavido. I'm on holiday atm though so it will have to wait a week or two.

And with regards to all the comments about my asking about 5.7 I just want to say that I'm ok not doing it. I find it a bit odd that it already accept only security fixes but it's not my repo or my policy.

@jackwh

jackwh commented Jul 21, 2019

Copy link
Copy Markdown
Contributor

Unless I'm misunderstanding, I don't think this change is backwards-compatible — it's broken the custom Markdown mail styling I was using in my app.

In src/Illuminate/Notifications/Messages/MailMessage.php, the $theme property is now being set:

/**
 * The current theme being used when generating emails.
 *
 * @var string|null
 */
public $theme = 'default';

Previously, the MailServiceProvider determined the Markdown theme based on your config file:

return new Markdown($this->app->make('view'), [
    'theme' => $config->get('mail.markdown.theme', 'default'),
    'paths' => $config->get('mail.markdown.paths', []),
]);

After this change, anyone who had changed their mail.php config item for mail.markdown.theme will no longer see their custom theme being used as the default. Instead, they'll have to manually specify which theme to use on every Notification class.

@troccoli

Copy link
Copy Markdown
Contributor Author

That's interesting. Which version are you using? The reason I submitted the PR was that I needed an easy way to change the theme for notification and I didn't find one in 5.7.

@troccoli troccoli deleted the add-template-theme-to-mail-notifications branch April 24, 2020 07:38
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.

8 participants