Notification class abstract

A notification (Laravel's Notification): via names the channels, and each channel reads its own method.

final class InvoicePaid extends Notification {
  InvoicePaid(this.invoice);
  final Invoice invoice;

  @override
  List<String> via(Object notifiable) => ['mail', 'database'];

  @override
  NotificationMail toMail(Object notifiable) => NotificationMail()
      .subject('Invoice paid')
      .line('We received your payment of ${invoice.total}.')
      .action('View invoice', 'https://example.com/invoices/${invoice.id}');

  @override
  Map<String, Object?> toDatabase(Object notifiable) =>
      {'invoice_id': invoice.id, 'total': invoice.total};
}

await user.notify(InvoicePaid(invoice));

Constructors

Notification()
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

broadcastAs() → String
The broadcast event name: Laravel's Illuminate\Notifications\Events\BroadcastNotificationCreated.
broadcastOn(Object notifiable) → List<String>
The channels to broadcast on; empty for the notifiable's own (private-App.Models.User.1, Laravel's receivesBroadcastNotificationsOn as a PrivateChannel).
broadcastType(Object notifiable) → String
The type sent with a broadcast: databaseType by default.
databaseType(Object notifiable) → String
The type column: Laravel stores the notification's class name, so the default is App\Notifications\<ClassName>.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toArray(Object notifiable) → Map<String, Object?>
toBroadcast(Object notifiable) → Map<String, Object?>?
For the broadcast channel: the data sent; toArray when null (Laravel's toBroadcast).
toDatabase(Object notifiable) → Map<String, Object?>?
For the database channel: the data column; toArray when null.
toMail(Object notifiable) → Object?
For the mail channel: a NotificationMail or a Mailable.
toString() → String
A string representation of this object.
inherited
via(Object notifiable) → List<String>
The channels to send on: mail, database, or a registered one.

Operators

operator ==(Object other) → bool
The equality operator.
inherited