How to Customize Laravel 5.4 Notification Email Templates (Header and Footer)
Alright, so I ran into this issue of setting up an email template for my Laravel 5.4 app. It was a ‘Welcome’ email, using the default Laravel template. The challenge was to change the header and footer of the template.
We all try to read through the documentation as quickly as possible and if that doesn’t work, after full 3 minutes of reading the documentation, we would switch to stackoverflow, or laracasts or any other forum, expecting ‘copy and paste’ ready code.
Web Hosting Recommendation
Many people have asked me about the hosting I am using. To be honest I tried different hosting accounts from shared, VPS and dedicated. In case you want some really affordable hosting I recommend Bluehost. I am also hosting some of my Laravel projects right there on this $3.95 shared account and it works great.
Continue …
Things are easy if you just want to change the text message, and you have many examples on how to do so, using the mail components. However I didn’t find any answers on how to change the default header and footer.
Components
Laravel 5.4 introduced Mailable components. You can read about it here.
<!-- /resources/views/alert.blade.php -->
<div class="alert alert-danger">
{{ $slot }}
</div>
This would be one alert component, which is basically a blade template. Then the {{ $slot }} would be a variable/place to drop your content from another template/component.
@component('alert')
<strong>Whoops!</strong> Something went wrong!
@endcomponent
Like that. This would render
<div class="alert alert-danger">
<strong>Whoops!</strong> Something went wrong!
</div>
Publish Vendor Publish
Initially Laravel will use their components hidden in the core of the framework, that you can export by doing
php artisan vendor:publish --tag=laravel-mail