Files
dockerank2/app/Models/UserNotification.php
T
2026-09-01 07:49:48 -03:00

39 lines
1001 B
PHP
Executable File

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class UserNotification extends Model
{
protected $fillable = ['user_id', 'type', 'title', 'message', 'is_read', 'read_at'];
protected $casts = [
'is_read' => 'boolean',
'read_at' => 'datetime',
];
public function user(): BelongsTo { return $this->belongsTo(User::class); }
public function markAsRead(): void
{
$this->update(['is_read' => true, 'read_at' => now()]);
}
public function typeIcon(): string
{
return match ($this->type) {
'payment_due' => '💰',
'payment_overdue' => '🔴',
'subscription_expiring' => '⚠️',
'subscription_expired' => '🚫',
'payment_received' => '✅',
'admin_message' => '📢',
'new_registration' => '👋',
default => '📌',
};
}
}