How can I solve "No hint path defined for [mail]." (customize email layout) on laravel?
Asked Answered
P

3

9

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?

Polivy answered 4/9, 2017 at 7:38 Comment(2)
try this command to publish mail directory from package to your views php artisan vendor:publish --tag=laravel-mailAgrology
@umefarooq, I have done that. But it's the samePolivy
A
24

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]);
}
Ayn answered 4/9, 2017 at 8:43 Comment(2)
Same problem as OP, I'm not using markdown but this solved the problem.Blais
If dont want to use pre-shiped markdown then whats the solutionLanford
W
3

In the recent version of Laravel, the trick happen in the content() method:

// change from :
return new Content(
    view: 'view.name', // ❌Nope     
);

// To :
return new Content( 
    markdown: 'view.name', // 🟢Yup 👍
);
Waldrup answered 28/9, 2023 at 16:3 Comment(0)
H
0

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.

Halo answered 23/7, 2019 at 15:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.