Search code examples
phplaravellaravel-8laravel-9

Change Laravel 8 Notification Salutation without publishing the template files



I would like to edit the 'regards, {application name}' part in the toMail Notifications without publishing the blade template files. Imo its an overkill to do so

Part in Question is here

I know Laravel provides several functions to change the contents of the Mail but this part seems to always stay the same unless edited via the template files.

Thank you in advance!


Solution

  • So after some digging through the files I found the solution and it's pretty easy:

     return (new MailMessage)
                ->from('info@test.com', 'Testorganisation')
                ->subject('Your mailsubject')
                ->greeting("Hello $notifiable->name,")
                ->salutation("You are welcome"); // Change this for a different salutation
    

    This results in this output
    It's handled via the subject-Function inside the SimpleMessage.php file located in /vendor/laravel/framework/src/Illuminate/Notifications/Messages/

    Hope this helps someone, since I didn't find a solution other than publishing the blade templates. I don't know when the function was added, but works in Laravel 8+