Performance: Notification channels (mail, database, SMS)
This affects how quickly notifications are delivered and how much server and network resources are used during notification processing.
Jump into concepts and practice - no test required
Notification::send($user, new InvoicePaid($invoice)); // queued notifications (notification implements ShouldQueue)
Notification::send($user, new InvoicePaid($invoice)); // sends mail and SMS synchronously| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous mail and SMS sending | 0 | 0 | 0 | [X] Bad |
| Queued mail and SMS sending | 0 | 0 | 0 | [OK] Good |
| Database notifications without indexes | 0 | 0 | 0 | [X] Bad |
| Database notifications with proper indexes | 0 | 0 | 0 | [OK] Good |
via.via method of a Laravel notification?via method must return an array of channel names as strings.['mail'] is correct; returning a string or function call is incorrect.public function toDatabase($notifiable) {
return [
'invoice_id' => 1234,
'amount' => 250
];
}toDatabase method returns an array of data saved in the notifications table.public function via($notifiable) {
return ['nexmo'];
}
public function toNexmo($notifiable) {
return (new NexmoMessage)->content('Hello!');
}NexmoMessage class must be imported with use statement or aliased; missing import causes error.via method implementations correctly sets all three channels?