Class
Opscale\NotificationCenter\Models\Audience
Extends Illuminate\Database\Eloquent\Model. Uses AudienceRepository, HasUlids, SoftDeletes, and ValidatorTrait.
Database table: notification_center_audiences
Attributes
ULID primary key, auto-generated on creation.
Human-readable name for the audience (e.g.
"Premium subscribers").Longer description explaining the purpose or composition of this audience.
Determines how the member profiles are resolved. Cast to the
AudienceType enum.Resolution criteria whose meaning depends on
type:- Static — not used; members are managed via the pivot table directly.
- Dynamic — a raw SQL query string that returns rows with an
idcolumn corresponding to profile IDs. - Segment — a comma-separated string of tag names used to match profiles via
Profile::withAnyTags().
text in the database; cast to array by Eloquent.Cached count of the resolved profiles. Updated automatically by
getProfiles() for Dynamic and Segment audiences. Defaults to 0.Timestamp of when the record was created.
Timestamp of the last update.
Soft-delete timestamp. Present when the record has been soft-deleted.
Enums
AudienceType
Opscale\NotificationCenter\Models\Enums\AudienceType
| Value | String | Description |
|---|---|---|
STATIC | 'Static' | A fixed, manually-curated list of profiles. Members are managed through the notification_center_audience_profile pivot table. |
DYNAMIC | 'Dynamic' | Membership is resolved at dispatch time by executing the raw SQL stored in criteria. Any profile whose ID is returned by the query is included. |
SEGMENT | 'Segment' | Membership is resolved by matching profile tags. The criteria field holds a comma-separated list of tag names; profiles with any matching tag are included. |
Relationships
profiles
ReturnsBelongsToMany — the Profile records explicitly attached to this audience (relevant for Static audiences). The pivot table is notification_center_audience_profile.
notifications
ReturnsBelongsToMany — the Notification records that target this audience via the notification_center_audience_notification pivot table.
Repository pattern
TheAudienceRepository trait mixed into this model provides the getProfiles() method, which resolves the correct set of profiles based on the audience type.
getProfiles()
Returns Illuminate\Database\Eloquent\Collection<Profile> — the resolved profiles for this audience.
total_members is a cached value and is only refreshed when getProfiles() is called for Dynamic and Segment types. For Static audiences it is not automatically maintained — update it manually if you need an accurate count.