*/ use HasFactory; protected $fillable = [ 'message', 'mode', 'recipient_count', 'sent_count', 'failed_count', 'skipped_count', 'laravel_batch_id', 'created_by', 'completed_at', ]; /** * @return array */ protected function casts(): array { return [ 'completed_at' => 'datetime', ]; } public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } public function sendLogs(): HasMany { return $this->hasMany(SmsSendLog::class); } public function isComplete(): bool { return $this->completed_at !== null; } public function processedCount(): int { return $this->sent_count + $this->failed_count + $this->skipped_count; } public function progressPercent(): int { if ($this->recipient_count === 0) { return 100; } return (int) min(100, round(($this->processedCount() / $this->recipient_count) * 100)); } }