dev update

This commit is contained in:
baodev0
2026-09-10 16:32:48 +07:00
parent 2365ef72e9
commit cd38c5d6d0
15 changed files with 483 additions and 191 deletions
+29
View File
@@ -17,6 +17,7 @@ class Template extends Model
protected $fillable = [
'type_id',
'scenario',
'key',
'format',
'invoice_template_id',
'name',
@@ -44,6 +45,9 @@ class Template extends Model
if ($this->scenario) {
Cache::forget(self::CACHE_PREFIX . $this->scenario);
}
if ($this->key) {
Cache::forget(self::CACHE_PREFIX . $this->key);
}
}
/** Danh sách variable hợp lệ khai báo trong metadata.variables, key theo variable key. */
@@ -59,6 +63,7 @@ class Template extends Model
}
public const SCENARIOS = [
'layout' => 'Bố cục Header/Footer (mặc định)',
'vm_credentials' => 'Khởi tạo dịch vụ',
'renewal_reminder' => 'Nhắc gia hạn',
'news_notification' => 'Thông báo tin tức',
@@ -102,6 +107,30 @@ class Template extends Model
return $this->belongsTo(self::class, 'invoice_template_id');
}
/**
* Wrap $contentHtml with the admin-editable "layout" template (scenario=layout),
* replacing its {{$content}} placeholder. Falls back to the static blade
* template-camp wrapper when no active layout template is configured.
*/
public static function renderWithLayout(?string $subject, string $contentHtml): string
{
$layout = self::where('scenario', 'layout')->where('status', 1)->first();
if (!$layout || !$layout->message) {
return view('emails.customer.template-camp', [
'content' => $contentHtml,
'emailSubject' => $subject,
])->render();
}
$body = str_replace('{{$content}}', $contentHtml, $layout->message);
return view('emails.customer.template-envelope', [
'body' => $body,
'emailSubject' => $subject,
])->render();
}
public function type()
{
return $this->belongsTo(\App\Models\Type::class);