Files
WitShop/app/Models/EmailTemplate.php
marcoandClaude Sonnet 4.6 5dad8b9324
Deploy to Production (witstore.wende.it) / deploy (push) Successful in 7s
Add email templates, page layouts, and shop themes (template system)
- E-Mail-Templates: DB-gespeicherte HTML-Templates mit {{placeholder}}-System,
  Admin-UI zum Bearbeiten von Betreff und Body, alle 4 Mailables aktualisiert
- Seiten-Layouts: 4 Layouts für CMS-Seiten (Standard, Sidebar, Volle Breite, Landing),
  Layout-Auswahl im Admin-Formular
- Shop-Themes: 5 Farbthemen via CSS-Variablen, Picker in Einstellungen
- Deployment: EmailTemplateSeeder wird automatisch beim Deploy ausgeführt

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-20 22:04:54 +02:00

35 lines
843 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class EmailTemplate extends Model
{
protected $fillable = ['key', 'label', 'subject', 'body', 'variables'];
protected $casts = ['variables' => 'array'];
public static function getByKey(string $key): ?self
{
return static::where('key', $key)->first();
}
public function renderBody(array $data): string
{
$body = $this->body;
foreach ($data as $k => $v) {
$body = str_replace('{{' . $k . '}}', (string) $v, $body);
}
return $body;
}
public function renderSubject(array $data): string
{
$subject = $this->subject;
foreach ($data as $k => $v) {
$subject = str_replace('{{' . $k . '}}', (string) $v, $subject);
}
return $subject;
}
}