Я пытаюсь изменить шаблон для электронных писем на старом веб-сайте, который я сделал, используя Laravel 5.4
Я в конечном итоге планирую обновить по крайней мере до Laravel 5.5 и, возможно, до Laravel 5.7 - но яне хочу делать это прямо сейчас, если в этом нет особой необходимости (это потребует значительных перезаписей некоторых моих контроллеров и много дополнительного тестирования)
Я запустил:
php artisan vendor:publish --tag=laravel-mail
Это создало файлы в resources/views/vendor/mail
Затем я отредактировал эти файлы и попытался отправить сообщение.Без изменений.
Затем я отредактировал файлы в vendor/laravel/framework/src/Illuminate/Mail/resources/views/
и отправил сообщение - появился новый шаблон.
Поэтому, несмотря на существование папки resources/views/vendor/mail
, Laravel все еще читаетиз папки vendor/
после запуска php artisan vendor:publish
.Как это исправить?Что я делаю не так?
Обновление
Некоторая дополнительная информация, на случай, если это поможет.Вот мой почтовый шаблон (resources/views/mail/email-a-friend.blade.php
):
@component('mail::message')
Your friend, {{ $senderName }}, has sent you information about a property they feel you might be interested in.
This property is listed by {{ config('app.name') }}. To view this property and more like it, please click the link below.
@if($agent->id !== $property->agent->id)
[{{ url($property->url()) }}?agent={{ $agent->first_name }}-{{ $agent->last_name }}]({{ url($property->url()) }}?agent={{ $agent->first_name }}-{{ $agent->last_name }})
@else
[{{ url($property->url()) }}]({{ url($property->url()) }})
@endif
@if($text != "")
They also sent this message:
@component('mail::panel')
{{ $text }}
@endcomponent
@endif
@endcomponent
Вот контроллер, который ставит электронную почту в очередь (app/http/Controllers/AjaxController.php
- только соответствующая функция):
public function emailAFriend(Request $request)
{
$property = \App\Models\Property\Property::find($request->input('property-id'));
$agent = $property->agent;
if ($request->input('agent-id') !== $agent->id) {
$agent = \App\User::find($request->input('agent-id'));
}
Mail::to($request->input('send-to'))
->queue(new \App\Mail\EmailAFriend($property, $agent, $request->input('name'), $request->input('reply-to'), $request->input('text')));
return Response::json("success", 200);
}
ВотMailable (app/Mail/EmailAFriend.php
):
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Models\Property\Property;
use App\User;
class EmailAFriend extends Mailable
{
use Queueable, SerializesModels;
public $subject = "Someone sent you a property!";
public $property;
public $agent;
public $senderName;
public $senderEmail;
public $text;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Property $property, User $agent, $name, $email, $text)
{
$this->subject = "$name sent you information about a property";
$this->property = $property;
$this->agent = $agent;
$this->senderName = $name;
$this->senderEmail = $email;
$this->text = $text;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('emails.email-a-friend')
->replyTo($this->senderEmail, $this->senderName)
->attachData(
$this->property->generatePdf(['agent' => $this->agent])->inline(),
"{$this->property->details->lot_size} acres in {$this->property->location->county} county.pdf",
[
'mime' => 'application/pdf'
]
);
}
}
В целях тестирования я использую sync
QueueDriver, поэтому он отправляется сразу после выполнения запроса AJAX.В производстве я использую database
QueueDriver.
Обновление 2
Компоненты:
resources/views/vendor/mail/html/message.blade.php
:
@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => config('app.url')])
<img src="{{ url('/img/layout/logo.png') }}" alt="{{ config('app.name') }}" />
@endcomponent
@endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
@if (isset($subcopy))
@slot('subcopy')
@component('mail::subcopy')
{{ $subcopy }}
@endcomponent
@endslot
@endif
{{-- Footer --}}
@slot('footer')
@component('mail::footer')
© {{ date('Y') }} {{ config('app.name') }}. All rights reserved.
@endcomponent
@endslot
@endcomponent
resources/views/vendor/mail/markdown/message.blade.php
:
@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => config('app.url')])
![{{ config('app.name') }}]({{ url('/img/layout/logo.png') }})
@endcomponent
@endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
@if (isset($subcopy))
@slot('subcopy')
@component('mail::subcopy')
{{ $subcopy }}
@endcomponent
@endslot
@endif
{{-- Footer --}}
@slot('footer')
@component('mail::footer')
© {{ date('Y') }} {{ config('app.name') }}. All rights reserved.
@endcomponent
@endslot
@endcomponent
Разница между этими двумя компонентами и компонентами по умолчанию (vendor/laravel/framework/src/Illuminate/Mail/resources/views/html/message.blade.php
и эквивалентом уценки) находится в заголовке:
{{ config('app.name') }}
replaced with:
<img src="{{ url('/img/layout/logo.png') }}" alt="{{ config('app.name') }}" />
Я пытался заменить название компании наих логотип.Когда я захожу в vendor/laravel/framework/src/Illuminate/Mail/resources/views/markdown/message.blade.php
и редактирую этот файл напрямую, я делаю вижу логотип в полученном электронном письме.Таким образом, несмотря на существование опубликованного компонента, он все еще читает из каталога vendor/
(и редактирование каталога vendor/
не годится, потому что тогда изменение не сохранится в рабочей среде)