8
votes

From here : Laravel 5.4 - How to customize notification email layout?

I try customize notification email layout

My code to send email like this :

public function toMail($notifiable)
{
    return (new MailMessage)
                ->subject('Test')
                ->view('vendor.mail.markdown.message',['data'=>$this->data]);
}

The view like this :

@component('mail::layout')
    {{-- Header --}}
    @slot('header')
        @component('mail::header', ['url' => config('app.url')])
            {{ config('app.name') }}
        @endcomponent
    @endslot

    {{-- Body --}}
    {{ $slot }} test

    {{-- Subcopy --}}
    @isset($subcopy)
        @slot('subcopy')
            @component('mail::subcopy')
                {{ $subcopy }}
            @endcomponent
        @endslot
    @endisset

    {{-- Footer --}}
    @slot('footer')
        @component('mail::footer')
            © {{ date('Y') }} {{ config('app.name') }}. All rights reserved.
        @endcomponent
    @endslot
@endcomponent

If the code executed, there exist error like this :

(2/2) ErrorException No hint path defined for [mail]. (View: C:\xampp\htdocs\myshop\resources\views\vendor\mail\markdown\message.blade.php)

How can I solve the error?

2
try this command to publish mail directory from package to your views php artisan vendor:publish --tag=laravel-mailumefarooq
@umefarooq, I have done that. But it's the sameSuccess Man

2 Answers

18
votes

If you are using markdown in your template, you need to use the ->markdown() method rather than the ->view() method on your MailMessage

public function toMail($notifiable)
{
    return (new MailMessage)
            ->subject('Test')
            ->markdown('vendor.mail.markdown.message', ['data' => $this->data]);
}
0
votes

In an application migrated through different Laravel versions (and now at 5.6) I had to modify the file config/mail.php, changing the parameter markdown/paths from resource_path('views/vendor/mail') to resource_path('views/vendor/mail/markdown'), so it found the base templates for my Markdown mails.