Performance: Creating notifications
This affects how quickly notifications are generated and delivered, impacting server response time and user experience.
Jump into concepts and practice - no test required
Notification::send($user, (new InvoicePaid($invoice))->onQueue('notifications'));Notification::send($user, new InvoicePaid($invoice));
| Pattern | Server Blocking | Queue Usage | User Response Delay | Verdict |
|---|---|---|---|---|
| Synchronous notification sending | High (blocks request) | No | Increases by 100-300ms | [X] Bad |
| Queued notification sending | Low (non-blocking) | Yes | Minimal delay | [OK] Good |
php artisan make:notification followed by the notification name.make:notify, create:notification, or generate:notification do not exist in Laravel.use App\Notifications\InvoicePaid; $user = User::find(1); $user->notify(new InvoicePaid($invoice));
notify() method sends the given notification instance to the user model.InvoicePaid notification.$user = User::find(5); $user->notify(InvoicePaid);
notify() method requires a notification instance, so InvoicePaid must be created with new InvoicePaid().User::find(5) is correct to get a user by ID, and notify() exists on the User model. User existence is not guaranteed but not a syntax error.via() method defines which channels the notification uses.