laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.2k stars 10.89k forks source link

Can not customize the mail components in HTML blade template (not Markdown template) #18467

Closed lvbeck closed 7 years ago

lvbeck commented 7 years ago

Description:

I want to customize the mail template components by following the guide of Laravel 5.4, but I get an Error after that:

ErrorException in FileViewFinder.php line 112: No hint path defined for [mail]. (View: /resources/views/emails/html/order/confirmed.blade.php)

Reason for using HTML template instead of Markdown :

For markdown template, I was unable to embed image in the mail because of this bug: https://github.com/laravel/framework/issues/17629

Steps To Reproduce:

  1. php artisan make:mail OrderConfirmed
  2. php artisan vendor:publish --tag=laravel-mail
  3. create a html blade template in /resources/views/emails/html/order/confirmed.blade.php
  4. use the blade template in App\Mail\OrderConfirmed.php

resources/views/emails/html/order/confirmed.blade.php:

@component('mail::message')
<h1>Order Confirmed</h1>
<p>Your order is confirmed!</p>

@component('mail::button', ['url' => $url])
View Order
@endcomponent

<p>
Thanks,<br>
{{ config('app.name') }}
</p>
@endcomponent

App\Mail\OrderConfirmed.php:

<?php
namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\URL;

use App\Order;

class OrderConfirmed extends Mailable
{
    use Queueable, SerializesModels; 

    /**
     * The order instance.
     *
     * @var Order
     */
    public $order;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.html.order.confirmed')->with(['url' => URL::to('order/show/'.$this->order->id)]);
    }
}
themsaid commented 7 years ago

These views are used to render the HTML version of the markdown email, I know it may be confusing a bit but these views are only available when you're sending a markdown email.

When you send a markdown email laravel creates an HTML version as well as a markdown version of your email, the html views you are referring are not publicly available as a blade template, they're only accessible from within the markdown email.

lvbeck commented 7 years ago

@themsaid sorry it's my misunderstanding, I will give markdown mail another try, thanks.

kyberkiller commented 7 years ago

Are you 'themsaid' saying blade rendering is only for markdown?