Skip to content

Commit

Permalink
Merge pull request #14350 from hammadzafar05/patch-3
Browse files Browse the repository at this point in the history
Document automatic event dispatching for database notifications
  • Loading branch information
danharrin authored Oct 7, 2024
2 parents 96c21dc + 4a1d90e commit 14d6979
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/notifications/docs/03-database-notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,16 @@ DatabaseNotifications::pollingInterval(null);

Alternatively, the package has a native integration with [Laravel Echo](https://laravel.com/docs/broadcasting#client-side-installation). Make sure Echo is installed, as well as a [server-side websockets integration](https://laravel.com/docs/broadcasting#server-side-installation) like Pusher.

Once websockets are set up, after sending a database notification you may dispatch a `DatabaseNotificationsSent` event, which will immediately fetch new notifications for that user:
Once websockets are set up, you can automatically dispatch a `DatabaseNotificationsSent` event by setting the `isEventDispatched` parameter to `true` when sending the notification. This will trigger the immediate fetching of new notifications for the user:

```php
use Filament\Notifications\Events\DatabaseNotificationsSent;
use Filament\Notifications\Notification;

$recipient = auth()->user();

Notification::make()
->title('Saved successfully')
->sendToDatabase($recipient);

event(new DatabaseNotificationsSent($recipient));
->sendToDatabase($recipient, isEventDispatched: true);
```

## Marking database notifications as read
Expand Down

0 comments on commit 14d6979

Please sign in to comment.