EmailTemplate.php 861 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Str;
  6. class EmailTemplate extends Model
  7. {
  8. use HasFactory;
  9. protected $fillable = [
  10. 'name',
  11. 'content',
  12. 'created_by'
  13. ];
  14. protected $casts = [
  15. 'created_at' => 'datetime',
  16. 'updated_at' => 'datetime',
  17. ];
  18. public function creator()
  19. {
  20. return $this->belongsTo(User::class, 'created_by');
  21. }
  22. public function scheduledEmails()
  23. {
  24. return $this->hasMany(EmailScheduled::class, 'template_id');
  25. }
  26. public function getWordCountAttribute()
  27. {
  28. return str_word_count(strip_tags($this->content));
  29. }
  30. public function getPreviewAttribute()
  31. {
  32. return Str::limit(strip_tags($this->content), 100);
  33. }
  34. }