mercredi 19 octobre 2016

How do you add images to emails generated by Laravel 5.3's new notification service?

Laravel 5.3 introduces a new service called notifications, allowing the construct of emails (among other notifications) via a simple fluent syntax:

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

What is an eloquent approach to adding images to the email notifications? I have already published the vendor files to modify the base template.

My thoughts currently stand at:

  • Extend Illuminate\Notifications\Messages\SimpleMessage as a new local class, along the lines SimpleMediaMessage with a few additional methods (along the lines of ->image(src, url, alt))
  • Modify the base template (or create one specific to SimpleMediaMessage that loops over the media array built up via ->image
  • Finally, register a custom channel to allow notifications to deliver notifications with images.

This seems quite heavy handed for something as simple as images in email. Am I missing something? Is there a better approach?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire