To use mail::button
type format, you have to create hint for that keyword, which is nowhere to be found in Laravel documentation.
As an alternate solution, this is how I'm using multiple layout for the Laravel notification:
Clone you existing mail (project/resources/views/vendor/mail) folder and customize the new layout. Inside mail folder you can customize the complete design. Files under this folder, provides blocks level changes to your email body.
Next, You have to clone email.blade.php file under notifications (project/resources/views/vendor/notifications), and customize it as per your need. This single file is the skeleton of your email.
Modify your email notifications to add view()
or markdown()
as per your need. In your Notification's 'toMail' function, chain the below line:
->view('vendor.notifications.custom_layout')
So, it will look like this:
return (new MailMessage)
->subject(__('emails/registration.subject'))
->greeting(__('emails/registration.failed.greetings', ['recipient' => $this->learner->username]))
->line(__('emails/registration.line_1'))
->line(__('emails/registration.line_2', ['username' => $this->username]))
->action(__('action.log_in'), "https://{$loginURL}")
->view('vendor.notifications.custom_layout');
- All the file naming convention will change from
mail::message
to vendor.custom_layout.html.message
This is how your custom file (under notifications folder) will look like:
@component('vendor.custom_layout.html.message')
{{-- Greeting --}}
@if (! empty($greeting))
# {{ $greeting }}
@else
@if ($level == 'error')
# @lang('Whoops!')
@else
# @lang('Hello!')
@endif
@endif
{{-- Intro Lines --}}
@foreach ($introLines as $line)
{!! $line !!}
@endforeach
{{-- Action Button --}}
@isset($actionText)
@component('vendor.custom_layout.html.button', ['url' => $actionUrl])
{{ $actionText }}
@endcomponent
@endisset
{{-- Outro Lines --}}
@foreach ($outroLines as $line)
{!! $line !!}
@endforeach
{{-- Salutation --}}
@if (! empty($salutation))
{{ $salutation }}
@else
{{ __('label.thank_you') }}<br>{{ __('label.xyz_team') }}
@endif
{{-- Subcopy --}}
@isset($actionText)
@component('vendor.custom_layout.html.subcopy')
{!! __('emails/common.footer_notice', ['actionText' => $actionText]) !!}
[{{ $actionUrl }}]({!! $actionUrl !!})
@endcomponent
@endisset
@endcomponent
These are the only changes which are required to make a customized view for your emails.