This commit is contained in:
baodev0
2026-10-05 09:30:24 +07:00
parent a1aeb88061
commit 1544629a1f
53 changed files with 1292 additions and 963 deletions
@@ -0,0 +1,25 @@
<?php
namespace App\Mail\Concerns;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Envelope;
trait BuildsTemplateEnvelope
{
protected function templateEnvelope(string $subject, array $mailConfig): Envelope
{
return new Envelope(
subject: $subject,
from: $this->templateAddress($mailConfig['from_email'] ?? null, $mailConfig['from_name'] ?? null),
replyTo: array_filter([$this->templateAddress($mailConfig['reply_to'] ?? null, $mailConfig['reply_to_name'] ?? null)]),
cc: $mailConfig['cc'] ?? [],
bcc: $mailConfig['bcc'] ?? [],
);
}
private function templateAddress(?string $email, ?string $name): ?Address
{
return $email ? new Address($email, $name) : null;
}
}
-21
View File
@@ -1,21 +0,0 @@
<?php
namespace App\Mail\Concerns;
use App\Services\Email\EmailTemplateService;
/**
* Render subject+html từ Template DB (EmailTemplateService) theo scenario.
* Không còn fallback về Blade view — nếu template thiếu/tắt hoặc chứa
* variable không hợp lệ, exception sẽ propagate rõ ràng thay vì gửi email rỗng.
*/
trait RequiresDbTemplate
{
private ?array $dbRendered = null;
/** @return array{subject: string, html: string} */
protected function renderFromTemplate(string $scenario, array $vars): array
{
return $this->dbRendered ??= app(EmailTemplateService::class)->preview($scenario, $vars);
}
}