Class
Opscale\NotificationCenter\Models\Subscription
Extends Illuminate\Database\Eloquent\Model. Uses HasUlids, SoftDeletes, and ValidatorTrait.
Database table: notification_center_subscriptions
Overview
ASubscription record stores a single verified contact point for a Profile on a specific notification channel. Each subscription has a type (the channel identifier, e.g. 'webpush', 'sms', 'email') and a contact value (the endpoint, phone number, or address for that channel).
Multiple subscriptions per profile are supported — a user might have a webpush subscription, an SMS subscription, and an email subscription. A unique constraint on (profile_id, type, contact) prevents duplicates.
Attributes
ULID primary key, auto-generated on creation.
Foreign key referencing
notification_center_profiles.id. Cascades on delete.The notification channel this subscription applies to (e.g.
'webpush', 'email', 'sms'). Matches the channel identifier keys used in config('notification-center.messages').The channel-specific contact address or endpoint. For example:
- webpush — the push subscription endpoint URL registered by the service worker.
- email — the recipient email address.
- sms / call / whatsapp — the recipient phone number.
- nova / card — the primary key of the notifiable user model.
Whether the contact address has been verified. Defaults to
false. Cast to boolean.Unsigned tiny integer (0–255) indicating dispatch priority when a profile has multiple subscriptions of the same type. Lower values indicate higher priority. Defaults to
5.Timestamp of when the subscription was created.
Timestamp of the last update.
Soft-delete timestamp. Present when the subscription has been soft-deleted.
Relationships
profile
ReturnsBelongsTo — the Profile that owns this subscription.
Unique constraint
The database enforces a composite unique index on(profile_id, type, contact). Attempting to insert a duplicate subscription for the same profile, channel, and contact will throw an integrity constraint violation.
Webpush subscriptions
When a user grants push notification permission in their browser and the service worker registers successfully, the browser provides a push subscription object containing:- endpoint — the push service URL (stored in
contact) - keys (p256dh, auth) — encryption keys used by the push server
Profile model includes the HasPushSubscriptions trait from laravel-notification-channels/webpush, which handles storing and retrieving these subscriptions.
updatePushSubscription() is provided by the HasPushSubscriptions trait and will create or update the subscription record automatically, preventing duplicates.Usage with notification routing
TheProfile::routeNotificationFor() method checks whether the dispatched notification implements getSubscription(). If so, it returns that subscription value directly to the channel driver instead of delegating to the default Notifiable routing:
getSubscription() from the base Notification class, which looks up the matching Subscription record by channel type: