trait Notifiable

Adds notification capabilities to a model.

This trait allows any model to send notifications through one or more channels (e.g., database, log, mail) using your Notification system.

Requirements/Assumptions:

  • The consuming model exposes an integer $id property (used by notifications()).
  • Channel drivers are registered in {\Core\Lib\Notifications\ChannelRegistry}.
  • Each Notification may optionally implement per-channel methods such as toDatabase(object $notifiable): array, toLog(object $notifiable): string, toMail(object $notifiable): array, etc. If a to{Channel} method is missing, notify() passes null as the message payload for that channel.

Methods

void
notify(Notification $notification, array|null $channels = null, array $payload = [])

Send a notification to this notifiable through one or more channels.

array
notifications()

Retrieve this notifiable's unread notifications, newest first.

Details

at line 49
void notify(Notification $notification, array|null $channels = null, array $payload = [])

Send a notification to this notifiable through one or more channels.

Resolves channels from the provided $channels argument or, if omitted, from $notification->via($this). For each channel, this method looks for a corresponding payload method on the notification named to{Channel} (e.g., toDatabase, toLog, toMail). The result (or null if the method does not exist) is placed under the message key, and the $payload array is included under meta. The combined payload is then sent to the channel driver resolved by {\Core\Lib\Notifications\ChannelRegistry::resolve()}.

Parameters

Notification $notification

The notification instance to send.

array|null $channels

Optional explicit list of channels to use. Each item may be either a Channel enum case or a lowercase string channel name (e.g. 'database'). When null, channels are taken from $notification->via($this).

array $payload

Optional supplemental metadata to include under the meta key for every channel (e.g., correlation IDs, debug flags). Defaults to an empty array.

Return Value

void

Exceptions

RuntimeException
Throwable

at line 90
array notifications()

Retrieve this notifiable's unread notifications, newest first.

Queries the notifications table for rows where notifiable_id = $this->id and read_at IS NULL, ordered by created_at DESC.

Return Value

array

An array of unread notification records (model instances) for this notifiable. Returns an empty array if none are found.