.cursor/skills/laravel-best-practices/rules/events-notifications.md
Laravel auto-discovers listeners by reading handle(EventType $event) type-hints. No manual registration needed in AppServiceProvider.
event:cache in Production DeployEvent discovery scans the filesystem per-request in dev. Cache it in production: php artisan optimize or php artisan event:cache.
ShouldDispatchAfterCommit Inside TransactionsWithout it, a queued listener may process before the DB transaction commits, reading data that doesn't exist yet.
class OrderShipped implements ShouldDispatchAfterCommit {}
Notifications often hit external APIs (email, SMS, Slack). Without ShouldQueue, they block the HTTP response.
class InvoicePaid extends Notification implements ShouldQueue
{
use Queueable;
}
afterCommit() on Notifications in TransactionsSame race condition as events — call afterCommit() to delay dispatch until the transaction commits.
$user->notify((new InvoicePaid($invoice))->afterCommit());
Mail and database notifications have different priorities. Use viaQueues() to route them to separate queues.
Avoid creating dummy models to send notifications to arbitrary addresses.
Notification::route('mail', '[email protected]')->notify(new SystemAlert());
HasLocalePreference on Notifiable ModelsLaravel automatically uses the user's preferred locale for all notifications and mailables — no per-call locale() needed.