Notification is the immutable message object that drivers receive.
A notification can carry:
id: a caller-provided id or a generated 32-character hex id;subject: optional short subject text;body: optional body text;recipients: zero or moreRecipientobjects or recipient payloads;template: optional template name;data: template or driver data;metadata: application and tracing context;tags: normalized unique labels;createdAt: creation time.
At least one of subject, body, or template must be present.
use CommonPHP\Notifications\Notification;
$notification = new Notification(
subject: 'Welcome',
body: 'Thanks for signing up.',
recipients: ['ada@example.com'],
metadata: ['source' => 'registration'],
tags: ['welcome'],
);Template notifications can be created with the named factory:
$notification = Notification::template(
'auth.password-reset',
['ada@example.com'],
['url' => $url],
subject: 'Reset your password',
);Notification mutation methods return new instances:
$localized = $notification
->withSubject('Bienvenue')
->withBody('Merci pour votre inscription.')
->withMetadata('locale', 'fr_CA')
->withTag('localized');Other copy methods include withRecipients(), withRecipient(), usingTemplate(), withData(), withoutData(), withMetadata(), withoutMetadata(), and withoutTag().
Drivers normally use the recipient list for their channel:
$emailRecipients = $notification->recipientsForChannel('email');This returns recipients whose channel is email plus recipients with no channel.