51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class AttendanceEmailTemplate extends Model
|
|
{
|
|
protected $table = 'email_templates';
|
|
protected $fillable = [
|
|
'code',
|
|
'variant',
|
|
'subject',
|
|
'body_html',
|
|
'is_active',
|
|
'updated_by',
|
|
'updated_at',
|
|
];
|
|
public $timestamps = false;
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'updated_by' => 'integer',
|
|
'updated_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Fetch an active template by code and variant, falling back to default.
|
|
*/
|
|
public function getTemplate(string $code, string $variant = 'default'): ?array
|
|
{
|
|
$row = self::query()
|
|
->where('code', $code)
|
|
->where('variant', $variant)
|
|
->where('is_active', true)
|
|
->first();
|
|
|
|
if ($row) {
|
|
return $row->toArray();
|
|
}
|
|
|
|
$row = self::query()
|
|
->where('code', $code)
|
|
->where('variant', 'default')
|
|
->where('is_active', true)
|
|
->first();
|
|
|
|
return $row ? $row->toArray() : null;
|
|
}
|
|
}
|