| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Str;
- class EmailTemplate extends Model
- {
- use HasFactory;
- protected $fillable = [
- 'name',
- 'content',
- 'created_by',
- ];
- protected $casts = [
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- ];
- public function creator()
- {
- return $this->belongsTo(User::class, 'created_by');
- }
- public function attachments()
- {
- return $this->hasMany(EmailTemplateAttachment::class, 'attachments');
- }
- public function scheduledEmails()
- {
- return $this->hasMany(EmailScheduled::class, 'template_id');
- }
- public function getWordCountAttribute()
- {
- return str_word_count(strip_tags($this->content));
- }
- public function getPreviewAttribute()
- {
- return Str::limit(strip_tags($this->content), 100);
- }
- }
|