Skip to main content

Class

Opscale\NotificationCenter\Models\Profile Extends Illuminate\Database\Eloquent\Model. Uses HasPushSubscriptions, HasTags, HasUlids, Notifiable, SoftDeletes, and ValidatorTrait. Database table: notification_center_profiles

Overview

A Profile is the Notification Center’s internal representation of a notifiable user. Rather than sending notifications directly to your application’s User model, the package dispatches them through Profile records. Each Profile is linked to your application’s notifiable model (e.g. User) via a polymorphic notifiable relationship. Because Profile uses Laravel’s Notifiable trait, it can be passed directly to Notification::send() or used as the target in any standard Laravel notification dispatch.

Attributes

id
string
required
ULID primary key, auto-generated on creation.
notifiable_type
string
required
The fully-qualified class name of the polymorphic notifiable model (e.g. App\Models\User). Part of the ulidMorphs pair.
notifiable_id
string
required
The ULID of the linked notifiable model instance. Part of the ulidMorphs pair.
created_at
Carbon\Carbon | null
Timestamp of when the profile was created.
updated_at
Carbon\Carbon | null
Timestamp of the last update.
deleted_at
Carbon\Carbon | null
Soft-delete timestamp. Present when the profile has been soft-deleted.
Channel-specific contact details (email address, phone number, push endpoint, etc.) are stored on Subscription records associated with the profile, not on the Profile itself.

Eager-loaded relationships

The $with property is set to ['notifiable', 'subscriptions'], so these two relationships are always loaded with every Profile query.

Relationships

notifiable

Returns MorphTo — the underlying application model (e.g. a User) that this profile represents.
$profile->notifiable; // App\Models\User (or any other notifiable model)

// Access user attributes through the relationship
echo $profile->notifiable->email;

subscriptions

Returns HasMany — the Subscription records associated with this profile. Each subscription represents a verified contact point for a specific channel.
$profile->subscriptions; // Illuminate\Database\Eloquent\Collection<Subscription>

deliveries

Returns HasMany — all Delivery records for notifications sent to this profile.
$profile->deliveries; // Illuminate\Database\Eloquent\Collection<Delivery>

audiences

Returns BelongsToMany — the Audience groups this profile belongs to, via the notification_center_audience_profile pivot table.
$profile->audiences; // Illuminate\Database\Eloquent\Collection<Audience>

Key methods

routeNotificationFor($driver, $notification = null)

Overrides the default Laravel routing logic. When the notification implements getSubscription(), that value is returned directly (used for webpush channel routing). Otherwise, it delegates to the parent Notifiable implementation.
driver
string
required
The notification channel driver name (e.g. 'mail', 'webpush').
notification
mixed
default:"null"
The notification instance being dispatched. If it exposes a getSubscription() method, that subscription is used as the routing target.
// Internally called by Laravel's notification dispatcher
$routingTarget = $profile->routeNotificationFor('webpush', $notification);

Tags (via spatie/laravel-tags)

Profile includes the HasTags trait from spatie/laravel-tags. Tags are used by Segment audiences to dynamically select profiles.
// Attach tags to a profile
$profile->attachTag('vip');
$profile->attachTags(['beta-tester', 'early-adopter']);

// Find profiles with any of the given tags
$profiles = Profile::withAnyTags(['vip', 'beta-tester'])->get();

Usage examples

Creating a profile for a user

use Opscale\NotificationCenter\Models\Profile;

$user = App\Models\User::find($userId);

$profile = Profile::create([
    'notifiable_type' => get_class($user),
    'notifiable_id'   => $user->id,
]);

Dispatching a notification to a profile

use Illuminate\Support\Facades\Notification;

// Profile implements Notifiable, so it can receive notifications directly
Notification::send($profile, new OrderShippedNotification($order));

Looking up a profile from a user

$profile = Profile::where('notifiable_type', App\Models\User::class)
    ->where('notifiable_id', $user->id)
    ->firstOrFail();

// Access all delivery history for this user
foreach ($profile->deliveries as $delivery) {
    echo $delivery->channel . ': ' . $delivery->status->value;
}
Because notifiable and subscriptions are always eager-loaded, querying large sets of profiles without additional constraints may result in significant memory usage. Apply without('notifiable', 'subscriptions') if you need a lightweight query.
Soft deletes are enabled. Deleting a profile in Nova soft-deletes the record; associated Subscription records are preserved until the profile is force-deleted.

Build docs developers (and LLMs) love