Skip to main content

Customizing the default Laravel notification template

Sending a notification with Laravel is easy, you just create the notification by running php artisan make:notification InvoicePaid --markdown=mail.invoice.paid, modify the generated blade-markdown file and you're good to go. But what if you want to customize the notification layout itself? How to replace the application name with something different?

Passing variables to the template files

Start by publishing the vendor files, as we don't want to change files within the vendor directory, by running the following command outlined in the Laravel documentation on Notifications: php artisan vendor:publish --tag=laravel-mail.

This is going to add the files to your resources/views directory. The notification template is split up into multiple sections we can customize to our heart's content. I wanted to conditionally add a company name and URL to the outgoing notification, so I added some logic to the resources/views/vendor/mail/html/header.blade.php file:

@props(['url', 'teamName' => null, 'teamUrl' => null])
<tr>
<td class="header">
@if((isset($teamName) && isset($teamUrl)) || (!isset($teamName) && isset($url)))
<a href="{{ isset($teamName) && isset($teamUrl) ? $teamUrl : $url }}" style="display: inline-block;">
@else
<span style="display: inline-block;">
@endif
@if (trim($slot) === 'Laravel')
<img src="https://laravel.com/img/notification-logo.png" class="logo" alt="Laravel Logo">
@else
{!! $slot !!}
@endif
@if((isset($teamName) && isset($teamUrl)) || (!isset($teamName) && isset($url)))
</a>
@else
</span>
@endif
</td>
</tr>

To be able to use the $teamName and $teamUrl variables in the header file, you have to pass and define them as props. In the parent file, resources/views/vendor/mail/html/message.blade.php we are going to make changes:

<x-mail::layout>
<x-slot:header>
<x-mail::header :url="config('app.url')" :teamName="$teamName ?? null" :teamUrl="$teamUrl ?? null">
{{ $teamName ?? config('app.name') }}
</x-mail::header>
</x-slot:header>

{!! $slot !!}

@isset($subcopy)
<x-slot:subcopy>
<x-mail::subcopy>
{!! $subcopy !!}
</x-mail::subcopy>
</x-slot:subcopy>
@endisset

<x-slot:footer>
<x-mail::footer>
© {{ date('Y') }} {{ config('app.name') }}. {{ __('All rights reserved.') }}
</x-mail::footer>
</x-slot:footer>
</x-mail::layout>

Here is where I pass the variables (if defined) as props to the header file I modified earlier. If all you need to do is change the display text / the slot, then you don't need to modify the header file at all as $teamName variable is going to be resolved and passed down as a value to the header component.

We're almost done! Now just pass the $teamName and '$teamUrl* variables to the message component. This can be accomplished by passing the variables through in the email blade-markdown file:

<x-mail::message :teamName="$teamName ?? null" :teamUrl="$teamUrl ?? null">
Your content here
</x-mail::message>

Now all that's left to do is to pass the variables to the markdown-blade view and you are off to the races:

->markdown('mail.invoice.paid', [
   'invoice' => $invoice,
   'teamName' => $team->name,
   'teamUrl' => $team->url,
])

And that's it! You can simplify the process further by using an array and passing it as a prop to the components where you need access to the values.

Published on August 15, 2025
Last modified on August 15, 2025

Did you like what you read? Feel free to share! Make sure to follow me on X (formerly known as Twitter) to stay in the loop.