You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EmailTemplate extends Model
|
||||
{
|
||||
protected $table = 'email_templates';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'subject',
|
||||
'body',
|
||||
'variables',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public static function getTemplate(string $name): ?self
|
||||
{
|
||||
return static::where('name', $name)
|
||||
->where('is_active', true)
|
||||
->first();
|
||||
}
|
||||
|
||||
public static function render(string $name, array $variables): ?array
|
||||
{
|
||||
$template = static::getTemplate($name);
|
||||
|
||||
if (! $template) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$subject = $template->subject;
|
||||
$body = $template->body;
|
||||
|
||||
foreach ($variables as $key => $value) {
|
||||
$subject = str_replace('{{' . $key . '}}', $value, $subject);
|
||||
$body = str_replace('{{' . $key . '}}', $value, $body);
|
||||
}
|
||||
|
||||
return [
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user