Markus
Markus

Reputation: 2062

Laravel Mail Message Components Prefix

I'm trying to customize my email temapltes for laravel. So I published the notifcations and mail vendors.

In the resources/views/vendor/notifications/email.blade.php file the framework calls components like this

@component('mail::button')

For what stands the mail:: prefix?

I've tryed to write my own component locatete under resources/views/vendor/mail/mycomponent.blade.php. So I also call it like the default components.

@component('mail::mycomponent')

It does not work. Here the error:

View [mycomponent] not found. (View: /resources/views/vendor/notifications/email.blade.php)

So my question is where the prefix mail:: points? Can I use it for my own components?

Upvotes: 1

Views: 7788

Answers (1)

Mihir Bhende
Mihir Bhende

Reputation: 9055

When you do php artisan vendor:publish --tag=laravel-mail larvel creates 2 directories inside resources/views/vendor/mail called html and markdown.

You need to have your component in there to make sure it's accessible inside email template.

If you want to create a component, you need to create 2 files : resources/views/vendor/mail/html/mycomponent.blade.php and resources/views/vendor/mail/markdown/mycomponent.blade.php

Markdown will have the data and slots whereas the html one will have actual html structure to render.

The mail:: prefix is Laravel's way to look for mail components, its not really a folder path in blade like we do layouts.default etc.

See documentation for more details.

Upvotes: 13

Related Questions