I followed this answer to publish the default email templates in my application with:
php artisan vendor:publish --tag=laravel-notifications
php artisan vendor:publish --tag=laravel-mail
This works great, but clearly there is some configuration options, such as:
{{-- Greeting --}}
@if (! empty($greeting))
# {{ $greeting }}
@else
@if ($level === 'error')
# @lang('Whoops!')
@else
# @lang('Hello!')
@endif
@endif
{{-- Salutation --}}
@if (! empty($salutation))
{{ $salutation }}
@else
@lang('Regards'),<br>{{ config('app.name') }}
@endif
Right now my emails are sending "Hello!" and "Regards" from the else section but clearly there is a way to set these defaults for email templates using variables. How do I set the $greeting
and $salutation
variables when sending emails?
The template you posted is the default template for notification mails. When creating such notification with for example:
php artisan make:notification InvoicePaid --markdown=mail.invoice.paid
A new InvoicePaid class is created at app/Notifications/InvoicePaid.php
.
This class contains a toMail()
method with the following contents:
return (new MailMessage)->markdown('mail.invoice.paid');
The MailMessage
class extends the SimpleMessage
class.
The SimpleMessage
class has the methods greeting()
and salutation()
which you can use to set the greeting or salutation.
For example:
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->greeting("Your custom greeting")
->salutation("Your salutation goes here")
->markdown('mail.invoice.paid');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With