reconstruction of the project
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\BaseModel;
|
||||
|
||||
class EmailTemplate extends Model
|
||||
class EmailTemplate extends BaseModel
|
||||
{
|
||||
protected $table = 'email_templates'; // Your CI model only had updated_at (no created_at)
|
||||
protected $table = 'email_templates';
|
||||
|
||||
// CI model didn't specify timestamps; keep off unless your table has created_at/updated_at.
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'variant',
|
||||
@@ -19,31 +22,30 @@ class EmailTemplate extends Model
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'updated_by' => 'integer',
|
||||
'updated_at' => 'datetime',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Fetch a template by code and variant, falling back to 'default' if needed.
|
||||
* Active only.
|
||||
* Equivalent of CI getActiveTemplates():
|
||||
* is_active=1, orderBy template_key ASC
|
||||
*/
|
||||
public static function getTemplate(string $code, string $variant = 'default'): ?self
|
||||
public static function getActiveTemplates()
|
||||
{
|
||||
// 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)
|
||||
->where('is_active', 1)
|
||||
->orderBy('template_key', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent of CI findByKey():
|
||||
* template_key = $key AND is_active=1
|
||||
*/
|
||||
public static function findByKey(string $key): ?self
|
||||
{
|
||||
return static::query()
|
||||
->where('template_key', $key)
|
||||
->where('is_active', 1)
|
||||
->first();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user