Files
boursecu_server/app/Models/AppNotification.php
T

62 lines
1.4 KiB
PHP
Raw Normal View History

2026-07-23 22:24:39 +03:30
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
2026-07-24 22:37:48 +03:30
use Illuminate\Database\Eloquent\Relations\BelongsTo;
2026-07-23 22:24:39 +03:30
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class AppNotification extends Model
{
use SoftDeletes;
protected $table = 'app_notifications';
protected $fillable = [
'title',
'body',
'severity',
'is_active',
'created_by',
2026-07-28 21:57:29 +03:30
'is_system',
2026-07-24 22:37:48 +03:30
'audience_type',
'segment_keys',
'audience_label',
'recipients_count',
2026-07-23 22:24:39 +03:30
];
protected $casts = [
'is_active' => 'boolean',
2026-07-28 21:57:29 +03:30
'is_system' => 'boolean',
2026-07-24 22:37:48 +03:30
'segment_keys' => 'array',
'recipients_count' => 'integer',
2026-07-23 22:24:39 +03:30
];
2026-07-28 21:57:29 +03:30
/** اعلان تراکنشی خودکار (نه ارسال دستی ادمین) */
public function scopeSystem($query)
{
return $query->where('is_system', true);
}
public function scopeAdminCreated($query)
{
return $query->where('is_system', false);
}
2026-07-23 22:24:39 +03:30
public function reads(): HasMany
{
return $this->hasMany(AppNotificationRead::class, 'notification_id');
}
2026-07-24 22:37:48 +03:30
public function recipients(): HasMany
{
return $this->hasMany(AppNotificationRecipient::class, 'notification_id');
}
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
2026-07-23 22:24:39 +03:30
}