update email template
This commit is contained in:
+27
-69
@@ -2,9 +2,8 @@
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Template;
|
||||
use App\Mail\Concerns\RequiresDbTemplate;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
@@ -12,86 +11,45 @@ use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CreateHosting extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
use Queueable, SerializesModels, RequiresDbTemplate;
|
||||
|
||||
protected $template = null;
|
||||
protected $data;
|
||||
/** @param int $template Không còn dùng — scenario cố định 'hosting_information'. Giữ tham số để không phá vỡ caller hiện tại. */
|
||||
public function __construct($template = 0, public $data = []) {}
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($template = 0, $data = [])
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->template = Template::find($template);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: str_replace("{\$product_name}", $this->data['product_name'], $this->template->subject),
|
||||
subject: $this->renderFromTemplate('hosting_information', $this->vars())['subject'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.template',
|
||||
with: [
|
||||
'template' => str_replace(
|
||||
[
|
||||
"{\$company_name}",
|
||||
"{\$company_logo}",
|
||||
"{\$client_name}",
|
||||
"{\$product_name}",
|
||||
"{\$product_billing}",
|
||||
"{\$product_price}",
|
||||
"{\$service_host}",
|
||||
"{\$service_username}",
|
||||
"{\$service_password}",
|
||||
"{\$service_password}",
|
||||
"{\$ftp_account}",
|
||||
"{\$ftp_password}",
|
||||
],
|
||||
[
|
||||
$this->data['company_name'],
|
||||
$this->data['company_logo'],
|
||||
$this->data['client_name'],
|
||||
$this->data['product_name'],
|
||||
$this->data['product_billing'],
|
||||
$this->data['product_price'],
|
||||
$this->data['service_host'],
|
||||
$this->data['service_username'],
|
||||
$this->data['service_password'],
|
||||
$this->data['service_due_exp'],
|
||||
$this->data['ftp_account'],
|
||||
$this->data['ftp_password'],
|
||||
],
|
||||
$this->template->message)
|
||||
]
|
||||
htmlString: $this->renderFromTemplate('hosting_information', $this->vars())['html'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attachments()
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function vars(): array
|
||||
{
|
||||
return [
|
||||
'company_name' => $this->data['company_name'] ?? '',
|
||||
'company_logo' => $this->data['company_logo'] ?? '',
|
||||
'client_name' => $this->data['client_name'] ?? '',
|
||||
'product_name' => $this->data['product_name'] ?? '',
|
||||
'product_billing' => $this->data['product_billing'] ?? '',
|
||||
'product_price' => $this->data['product_price'] ?? '',
|
||||
'service_host' => $this->data['service_host'] ?? '',
|
||||
'service_username'=> $this->data['service_username'] ?? '',
|
||||
'service_password'=> $this->data['service_password'] ?? '',
|
||||
'service_due_exp' => $this->data['service_due_exp'] ?? '',
|
||||
'ftp_account' => $this->data['ftp_account'] ?? '',
|
||||
'ftp_password' => $this->data['ftp_password'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user