Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/05-panel-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,23 @@ public function panel(Panel $panel): Panel
}
```

You may also choose to disable a notification for a specific HTTP status code, such as `503`, by passing that status code to the `hideErrorNotification` method:

```php
use Filament\Panel;

public function panel(Panel $panel): Panel
{
return $panel
// ...
->registerErrorNotification(
title: 'An error occurred',
body: 'Please try again later.',
)
->hideErrorNotification(503);
}
```

You can also enable or disable error notifications for specific pages in a panel by setting the `$hasErrorNotifications` property on the page class:

```php
Expand Down Expand Up @@ -565,3 +582,24 @@ class Dashboard extends BaseDashboard
// ...
}
```

You may also choose to disable a notification for a specific HTTP status code, such as `503`, by passing that status code to the `hideErrorNotification` method:

```php
use Filament\Pages\Dashboard as BaseDashboard;

class Dashboard extends BaseDashboard
{
protected function setUpErrorNotifications(): void
{
$this->registerErrorNotification(
title: 'An error occurred',
body: 'Please try again later.',
);

$this->hideErrorNotification(503);
}

// ...
}
```
8 changes: 6 additions & 2 deletions packages/panels/resources/js/error-notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ document.addEventListener('livewire:init', () => {
}
}

preventDefault()

const errorNotification =
errorNotifications[status] ?? errorNotifications['']

if (errorNotification.hidden === true) {
return
}

preventDefault()

new FilamentNotification()
.title(errorNotification.title)
.body(errorNotification.body)
Expand Down
12 changes: 12 additions & 0 deletions packages/panels/src/Pages/Concerns/HasErrorNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ public function registerErrorNotification(string $title, ?string $body = null, ?
$this->errorNotifications[$statusCode] = [
'title' => $title,
'body' => $body,
'hidden' => false,
];

return $this;
}

public function hideErrorNotification(int $statusCode): static
{
$this->errorNotifications[$statusCode] = [
'title' => null,
'body' => null,
'hidden' => true,
];

return $this;
Expand Down
12 changes: 12 additions & 0 deletions packages/panels/src/Panel/Concerns/HasErrorNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public function registerErrorNotification(string | Closure $title, string | Clos
$this->errorNotifications[$statusCode] = [
'title' => $title,
'body' => $body,
'hidden' => false,
];

return $this;
}

public function hideErrorNotification(int $statusCode): static
{
$this->errorNotifications[$statusCode] = [
'title' => null,
'body' => null,
'hidden' => true,
];

return $this;
Expand Down
Loading