49 lines
1.2 KiB
PHP
Executable File
49 lines
1.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class EmailTemplate extends Model
|
|
{
|
|
protected $table = 'email_templates'; // Your CI model only had updated_at (no created_at)
|
|
public $timestamps = false;
|
|
protected $fillable = [
|
|
'code',
|
|
'variant',
|
|
'subject',
|
|
'body_html',
|
|
'is_active',
|
|
'updated_by',
|
|
'updated_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'updated_by' => 'integer',
|
|
'updated_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Fetch a template by code and variant, falling back to 'default' if needed.
|
|
* Active only.
|
|
*/
|
|
public static function getTemplate(string $code, string $variant = 'default'): ?self
|
|
{
|
|
// Try exact active
|
|
$row = static::query()
|
|
->where('code', $code)
|
|
->where('variant', $variant)
|
|
->where('is_active', true)
|
|
->first();
|
|
|
|
if ($row) return $row;
|
|
|
|
// Fallback to default variant
|
|
return static::query()
|
|
->where('code', $code)
|
|
->where('variant', 'default')
|
|
->where('is_active', true)
|
|
->first();
|
|
}
|
|
} |