Files
2025-11-30 11:57:22 +01:00

91 lines
2.1 KiB
PHP

<?php
namespace Paymenter\Extensions\Others\ContactPage\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class ContactMessage extends Model
{
protected $table = 'ext_contact_messages';
protected $fillable = [
'name',
'email',
'subject',
'message',
'status',
'admin_notes',
'ip_address',
'user_agent',
'read_at',
'replied_at',
];
protected $casts = [
'read_at' => 'datetime',
'replied_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
public function scopeUnread(Builder $query): Builder
{
return $query->where('status', 'unread');
}
public function scopeRead(Builder $query): Builder
{
return $query->where('status', 'read');
}
public function scopeReplied(Builder $query): Builder
{
return $query->where('status', 'replied');
}
public function markAsRead(): void
{
$this->update([
'status' => 'read',
'read_at' => now(),
]);
}
public function markAsReplied(): void
{
$this->update([
'status' => 'replied',
'replied_at' => now(),
]);
}
public function archive(): void
{
$this->update([
'status' => 'archived',
]);
}
public function getStatusColorAttribute(): string
{
return match ($this->status) {
'unread' => 'danger',
'read' => 'warning',
'replied' => 'success',
'archived' => 'gray',
default => 'gray',
};
}
public function getFormattedStatusAttribute(): string
{
return match ($this->status) {
'unread' => 'Unread',
'read' => 'Read',
'replied' => 'Replied',
'archived' => 'Archived',
default => ucfirst($this->status),
};
}
}