Update dependencies
Composer: Laravel 13.43, Octane 2.25, Fortify 1.43 and Pest 5.3.7, with the packages they bring (70 in all). This fixes the advisories in Laravel and the Symfony components. npm: Vite 8.3.8 with Rolldown 1.2.19, Playwright 1.65.1 and chokidar 6. The asset build, CI and the dev container use Node.js 26. The dev image also has git for Composer. Both audits are clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
# Events and Notifications Best Practices
|
||||
# Events and notifications best practices
|
||||
|
||||
## Rely on Event Discovery
|
||||
## Rely on event discovery
|
||||
|
||||
Laravel discovers listeners in the configured listener directories by inspecting type-hinted event arguments on `handle()` or `__invoke()` methods. Register listeners manually only when discovery is disabled, the listener is outside those directories, or explicit registration is clearer.
|
||||
|
||||
## Cache Event Discovery During Production Deployment
|
||||
## Cache event discovery during production deployment
|
||||
|
||||
Cache discovered listeners during production deployment with `php artisan optimize` or `php artisan event:cache`. Rebuild the cache whenever listener definitions change.
|
||||
|
||||
## Use `ShouldDispatchAfterCommit` Inside Transactions
|
||||
## Use `ShouldDispatchAfterCommit` inside transactions
|
||||
|
||||
When an event is dispatched inside a database transaction, `ShouldDispatchAfterCommit` delays dispatch until all open database transactions commit. If a transaction rolls back, Laravel discards the event. This affects synchronous and queued listeners; it is not limited to queue timing.
|
||||
When you dispatch an event inside a database transaction, `ShouldDispatchAfterCommit` delays dispatch until all open database transactions commit. If a transaction rolls back, Laravel discards the event. The delay affects synchronous and queued listeners. It is not limited to queue timing.
|
||||
|
||||
```php
|
||||
class OrderShipped implements ShouldDispatchAfterCommit {}
|
||||
```
|
||||
|
||||
## Queue Slow Notifications
|
||||
## Queue slow notifications
|
||||
|
||||
Queue notifications that call external services, such as email, text messaging, or Slack, when they do not need to complete before the response. Keep a notification synchronous when immediate completion or failure feedback is part of the operation.
|
||||
|
||||
@@ -27,19 +27,19 @@ class InvoicePaid extends Notification implements ShouldQueue
|
||||
}
|
||||
```
|
||||
|
||||
## Dispatch Queued Notifications After Commit
|
||||
## Dispatch queued notifications after commit
|
||||
|
||||
A queued notification sent inside a database transaction can run before the transaction commits. Call `afterCommit()` on the queued notification, or enable the queue connection's `after_commit` option, when its delivery depends on committed data. This setting has no scheduling effect on a synchronous notification.
|
||||
A queued notification sent inside a database transaction can run before the transaction commits. Call `afterCommit()` on the queued notification, or enable the queue connection's `after_commit` option, when its delivery depends on committed data. Neither option has a scheduling effect on a synchronous notification.
|
||||
|
||||
```php
|
||||
$user->notify((new InvoicePaid($invoice))->afterCommit());
|
||||
```
|
||||
|
||||
## Route Notification Channels to Dedicated Queues
|
||||
## Route notification channels to dedicated queues
|
||||
|
||||
Different notification channels can have different latency and priority requirements. Implement `viaQueues()` when channels should use separate queues.
|
||||
|
||||
## Use On-Demand Notifications for Non-User Recipients
|
||||
## Use on-demand notifications for non-user recipients
|
||||
|
||||
Avoid creating dummy models to send notifications to arbitrary addresses.
|
||||
|
||||
@@ -47,6 +47,6 @@ Avoid creating dummy models to send notifications to arbitrary addresses.
|
||||
Notification::route('mail', 'admin@example.com')->notify(new SystemAlert());
|
||||
```
|
||||
|
||||
## Implement `HasLocalePreference` on Notifiable Models
|
||||
## Implement `HasLocalePreference` on notifiable models
|
||||
|
||||
Implement `HasLocalePreference::preferredLocale()` on a notifiable model when notifications and mailables should use the recipient's locale. Laravel also preserves that locale for queued delivery. An explicit `locale()` call can still override the preference for an individual notification.
|
||||
|
||||
Reference in New Issue
Block a user