From 8e473b1240002ca297e687b5390353b648c1bf13 Mon Sep 17 00:00:00 2001 From: jon Date: Sat, 1 Jun 2024 16:06:00 +0100 Subject: [PATCH] feat: Allow share default namespace to be changed --- config/inertia-flash.php | 1 + src/Notification/Concerns/HasNotificationDataViaChannel.php | 2 +- src/Notification/Concerns/HasNotificationDispatcher.php | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config/inertia-flash.php b/config/inertia-flash.php index 4395ee0..a1c786e 100644 --- a/config/inertia-flash.php +++ b/config/inertia-flash.php @@ -69,6 +69,7 @@ // Defaults for the notification 'defaults' => [ + 'namespace' => 'flashNotifications', 'read_route' => 'notification.read', 'type' => Flavorly\InertiaFlash\Notification\Enums\NotificationTypeEnum::Flash, 'level' => Flavorly\InertiaFlash\Notification\Enums\NotificationLevelEnum::Info, diff --git a/src/Notification/Concerns/HasNotificationDataViaChannel.php b/src/Notification/Concerns/HasNotificationDataViaChannel.php index 9db8ec7..5b8bd23 100644 --- a/src/Notification/Concerns/HasNotificationDataViaChannel.php +++ b/src/Notification/Concerns/HasNotificationDataViaChannel.php @@ -18,7 +18,7 @@ trait HasNotificationDataViaChannel /** * The namespace where the notification will be dispatched when sharing with inertia */ - public string $viaInertiaNamespace = 'notifications'; + public ?string $viaInertiaNamespace = null; /** * Routes the notification to the given channel, defaults to Broadcast & Database diff --git a/src/Notification/Concerns/HasNotificationDispatcher.php b/src/Notification/Concerns/HasNotificationDispatcher.php index 6f22729..d0d5262 100644 --- a/src/Notification/Concerns/HasNotificationDispatcher.php +++ b/src/Notification/Concerns/HasNotificationDispatcher.php @@ -97,7 +97,8 @@ protected function dispatchViaInertia(): void // Noop, we dont want to share via Inertia on console if ($this->via->contains(NotificationViaEnum::Inertia) || $this->via->contains('inertia')) { inertia_flash()->append( - $this->viaInertiaNamespace, + // @phpstan-ignore-next-line + $this->viaInertiaNamespace ?? config('inertia-flash.notifications.defaults.namespace', 'flashNotifications'), $this->toArray() ); }