update email template

This commit is contained in:
baodev0
2026-09-09 16:56:22 +07:00
parent d3d9f76ba0
commit 2365ef72e9
210 changed files with 6335 additions and 4688 deletions
+20 -56
View File
@@ -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,73 +11,38 @@ use Illuminate\Queue\SerializesModels;
class ExpiryService 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 'service_expiry'. 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: $this->template->subject
subject: $this->renderFromTemplate('service_expiry', $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}",
"{\$service_due_exp}",
"{\$service_remaining}"
],
[
$this->data['company_name'],
$this->data['company_logo'],
$this->data['client_name'],
$this->data['product_name'],
$this->data['service_due_exp'],
$this->data['service_remaining'],
],
$this->template->message)
]
htmlString: $this->renderFromTemplate('service_expiry', $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'] ?? '',
'product_name' => $this->data['product_name'] ?? '',
'service_due_exp' => $this->data['service_due_exp'] ?? '',
'service_remaining' => $this->data['service_remaining'] ?? '',
];
}
}