| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class UserNotification extends Model
- {
- use HasFactory;
- public const TYPE_PLATFORM = 'platform';
- public const TYPE_RECLAMATION = 'reclamation';
- public const TYPE_SCHEDULE = 'schedule';
- public const TYPE_NAMES = [
- self::TYPE_PLATFORM => 'Площадки',
- self::TYPE_RECLAMATION => 'Рекламации',
- self::TYPE_SCHEDULE => 'График монтажей',
- ];
- public const TYPE_COLORS = [
- self::TYPE_PLATFORM => 'primary',
- self::TYPE_RECLAMATION => 'success',
- self::TYPE_SCHEDULE => 'warning',
- ];
- public const EVENT_CREATED = 'created';
- public const EVENT_STATUS_CHANGED = 'status_changed';
- public const EVENT_SCHEDULE_ADDED = 'schedule_added';
- public const EVENT_NAMES = [
- self::EVENT_CREATED => 'Создание',
- self::EVENT_STATUS_CHANGED => 'Смена статуса',
- self::EVENT_SCHEDULE_ADDED => 'Добавлено в график',
- ];
- public const DEFAULT_SORT_BY = 'created_at';
- public const DEFAULT_ORDER_BY = 'desc';
- protected $fillable = [
- 'user_id',
- 'type',
- 'event',
- 'title',
- 'message',
- 'message_html',
- 'data',
- 'read_at',
- ];
- protected function casts(): array
- {
- return [
- 'data' => 'array',
- 'read_at' => 'datetime',
- ];
- }
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- public function isRead(): bool
- {
- return $this->read_at !== null;
- }
- public function getTypeNameAttribute(): string
- {
- return self::TYPE_NAMES[$this->type] ?? $this->type;
- }
- public function getEventNameAttribute(): string
- {
- return self::EVENT_NAMES[$this->event] ?? $this->event;
- }
- }
|