'array', 'sent_at' => 'datetime', ]; /** * Scope: 已发送的邮件 */ public function scopeSuccessful(Builder $query): Builder { return $query->where('status', 'sent'); } /** * Scope: 失败的邮件 */ public function scopeFailed(Builder $query): Builder { return $query->where('status', 'failed'); } /** * Scope: 待发送的邮件 */ public function scopePending(Builder $query): Builder { return $query->where('status', 'pending'); } /** * 获取状态文本 */ public function getStatusTextAttribute(): string { return match($this->status) { 'sent' => '已发送', 'failed' => '失败', 'pending' => '待发送', default => '未知', }; } /** * 获取状态颜色类 */ public function getStatusColorClassAttribute(): string { return match($this->status) { 'sent' => 'bg-green-100 text-green-600', 'failed' => 'bg-red-100 text-red-600', 'pending' => 'bg-yellow-100 text-yellow-600', default => 'bg-gray-100 text-gray-600', }; } }