Update 03-database-notifications.md

This commit is contained in:
Dan Harrin
2024-04-22 13:48:19 +01:00
committed by GitHub
parent 68151060d1
commit 5e7796a19c
@@ -3,7 +3,9 @@ title: Database notifications
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
## Overview
<AutoScreenshot name="notifications/database" alt="Database notifications" version="3.x" />
## Setting up the notifications database table
Before we start, make sure that the [Laravel notifications table](https://laravel.com/docs/notifications#database-prerequisites) is added to your database:
@@ -19,15 +21,17 @@ php artisan notifications:table
> If you're using UUIDs for your `User` model, make sure that your `notifiable` column is using `uuidMorphs()`: `$table->uuidMorphs('notifiable')`.
To add database notifications to your app, you must add a new Livewire component to your Blade layout:
## Rendering the database notifications modal
> If you want to add database notifications to a panel, [follow this part of the guide](#adding-database-notifications-to-a-panel).
If you'd like to render the database notifications modal outside of the [Panel Builder](../panels), you'll need to add a new Livewire component to your Blade layout:
```blade
@livewire('database-notifications')
```
<AutoScreenshot name="notifications/database" alt="Database notifications" version="3.x" />
Database notifications will be rendered within a modal. To open this modal, you must have a "trigger" button in your view. Create a new trigger button component in your app, for instance at `/resources/views/filament/notifications/database-notifications-trigger.blade.php`:
To open the modal, you must have a "trigger" button in your view. Create a new trigger button component in your app, for instance at `/resources/views/filament/notifications/database-notifications-trigger.blade.php`:
```blade
<button type="button">
@@ -47,9 +51,9 @@ DatabaseNotifications::trigger('filament.notifications.database-notifications-tr
Now, click on the trigger button that is rendered in your view. A modal should appear containing your database notifications when clicked!
## Enabling database notifications
### Adding the database notifications modal to a panel
If you'd like to receive database notifications, you can enable them in the configuration:
You can enable database notifications in a panel's [configuration](../panels/configuration):
```php
use Filament\Panel;
@@ -62,19 +66,7 @@ public function panel(Panel $panel): Panel
}
```
You may also control database notification polling:
```php
use Filament\Panel;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->databaseNotifications()
->databaseNotificationsPolling('30s');
}
```
To learn more, visit the [Panel Builder documentation](../panels/notifications).
## Sending database notifications