Files
glastree/app/Models/Notifica.php
T

32 lines
705 B
PHP
Raw Normal View History

2026-05-26 08:14:29 +02:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Notifica extends Model
{
protected $table = 'notifiche';
protected $fillable = ['user_id', 'tipo', 'titolo', 'messaggio', 'link', '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 scopeUnread($query)
{
return $query->where('is_read', false);
}
}