| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Casts\Attribute;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class NotificationDeliveryLog extends Model
- {
- use HasFactory;
- public const CHANNEL_IN_APP = 'in_app';
- public const CHANNEL_BROWSER = 'browser';
- public const CHANNEL_PUSH = 'push';
- public const CHANNEL_EMAIL = 'email';
- public const STATUS_SENT = 'sent';
- public const STATUS_FAILED = 'failed';
- public const STATUS_SKIPPED = 'skipped';
- public const STATUS_DEAD_LETTER = 'dead_letter';
- public const CHANNEL_LABELS = [
- self::CHANNEL_IN_APP => 'В приложении',
- self::CHANNEL_BROWSER => 'Браузер',
- self::CHANNEL_PUSH => 'Push',
- self::CHANNEL_EMAIL => 'Email',
- ];
- public const STATUS_LABELS = [
- self::STATUS_SENT => 'Отправлено',
- self::STATUS_FAILED => 'Ошибка',
- self::STATUS_SKIPPED => 'Пропущено',
- self::STATUS_DEAD_LETTER => 'Dead letter',
- ];
- public const DEFAULT_SORT_BY = 'created_at';
- public const DEFAULT_ORDER_BY = 'desc';
- protected $fillable = [
- 'user_notification_id',
- 'user_id',
- 'channel',
- 'status',
- 'attempt',
- 'message',
- 'error',
- ];
- protected function channel(): Attribute
- {
- return Attribute::make(
- get: fn($value) => self::CHANNEL_LABELS[$value] ?? $value,
- );
- }
- protected function status(): Attribute
- {
- return Attribute::make(
- get: fn($value) => self::STATUS_LABELS[$value] ?? $value,
- );
- }
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- public function userNotification(): BelongsTo
- {
- return $this->belongsTo(UserNotification::class);
- }
- }
|