Issue
I have a Laravel mailable like this:
...
public function build()
{
return $this->subject('Ticket Created ['.$this->ticket->ticket_code.']')
->view('emails.support.ticketcreated')->with([
'ticket' => $this->ticket
]);
}
Then I have a template for the email in my views directory:
<div class="card">
<div class="card-header bg-dark">
Ticket Created [{{ $ticket->ticket_code }}]
</div>
<div class="card-body">
<p>Thanks for creating a ticket! We will get back to you as soon as possible</p>
<p><a href="{{ $ticket->url }}">To view your ticket click here</a></p>
</div>
</div>
I want to wrap this in the default Laravel email template (so put all the above into the $slot
section in the layout)
I've published the Laravel email templates using:
php artisan vendor:publish --tag=laravel-mail
And I can see the layout file that I want to use under:
resources/views/vendor/mail/html/layout.blade.php
The problem is I can't seem to use this layout.
I've tried the following (but all have failed):
Wrapping the email template with but then it just tries to use my app layout (not the mail layout).
Using
@extends('vendor.mail.html.layout')
and@section('slot')
Tried adding ->layout('vendor.mail.html.layout'); to the end of the view() in mailable
build()
(just gives error method not found)
How can I use this layout for my emails. Note that I don't want to create a separate duplicate layout as then I'll have two layouts to manage.
Solution
Default Email Template Layout In Laravel Here is the official link of : Writing Markdown Messages
Here is my Mail Controller
<?php
namespace App\Mail;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NewUserRegistration extends Mailable
{
use Queueable, SerializesModels;
protected $user;
/**
* Create a new message instance.
*
* @param $user
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->to($this->user->email,$this->user->first_name.' '.$this->user->last_name)
->cc('ccemail@ccemail.com','CC USER NAME')
->from(env('MAIL_FROM_ADDRESS'),env('MAIL_FROM_NAME'))
->subject('subject_of_your_email')
->markdown('emails.registration',[ // This is very important line
'first_name' => $this->user->first_name,
'last_name' => $this->user->last_name,
]);
}
}
This is another controller from where i am executing my email
$getUserData = User::where('id',$userId)->first();
Mail::to($getUserData)->send(new NewUserRegistration($getUserData));
Answered By - Vipertecpro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.