Notifiable
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
$idproperty (used bynotifications()). - 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 ato{Channel}method is missing,notify()passesnullas themessagepayload for that channel.
Methods
Send a notification to this notifiable through one or more channels.
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()}.
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.