diff --git a/config/inertia-flash.php b/config/inertia-flash.php index 8050690..90f6919 100644 --- a/config/inertia-flash.php +++ b/config/inertia-flash.php @@ -72,7 +72,7 @@ 'timeout' => 5000, 'namespace' => 'flashNotifications', 'read_route' => 'notification.read', - 'type' => Flavorly\InertiaFlash\Notification\Enums\NotificationTypeEnum::Flash, + 'kind' => Flavorly\InertiaFlash\Notification\Enums\NotificationKindEnum::Flash, 'level' => Flavorly\InertiaFlash\Notification\Enums\NotificationLevelEnum::Info, 'via' => [ //Flavorly\InertiaFlash\Notification\Enums\NotificationViaEnum::Inertia, diff --git a/src/Notification/Concerns/HasNotificationDataType.php b/src/Notification/Concerns/HasNotificationDataKind.php similarity index 63% rename from src/Notification/Concerns/HasNotificationDataType.php rename to src/Notification/Concerns/HasNotificationDataKind.php index 558c88f..7380200 100644 --- a/src/Notification/Concerns/HasNotificationDataType.php +++ b/src/Notification/Concerns/HasNotificationDataKind.php @@ -2,21 +2,21 @@ namespace Flavorly\InertiaFlash\Notification\Concerns; -use Flavorly\InertiaFlash\Notification\Enums\NotificationTypeEnum; +use Flavorly\InertiaFlash\Notification\Enums\NotificationKindEnum; -trait HasNotificationDataType +trait HasNotificationDataKind { /** * How the frontend should handle the notification, default is Flash */ - public NotificationTypeEnum $type = NotificationTypeEnum::Flash; + public NotificationKindEnum $kind = NotificationKindEnum::Flash; /** * Sets the notification type */ - public function type(NotificationTypeEnum $kind): static + public function kind(NotificationKindEnum $kind): static { - $this->type = $kind; + $this->kind = $kind; return $this; } @@ -26,7 +26,7 @@ public function type(NotificationTypeEnum $kind): static */ public function flash(): static { - $this->type = NotificationTypeEnum::Flash; + $this->kind = NotificationKindEnum::Flash; return $this; } @@ -36,7 +36,7 @@ public function flash(): static */ public function dialog(): static { - $this->type = NotificationTypeEnum::Dialog; + $this->kind = NotificationKindEnum::Dialog; return $this; } @@ -46,7 +46,7 @@ public function dialog(): static */ public function toast(): static { - $this->type = NotificationTypeEnum::Toast; + $this->kind = NotificationKindEnum::Toast; return $this; } diff --git a/src/Notification/Enums/NotificationTypeEnum.php b/src/Notification/Enums/NotificationKindEnum.php similarity index 80% rename from src/Notification/Enums/NotificationTypeEnum.php rename to src/Notification/Enums/NotificationKindEnum.php index b5c558b..14474b6 100644 --- a/src/Notification/Enums/NotificationTypeEnum.php +++ b/src/Notification/Enums/NotificationKindEnum.php @@ -2,7 +2,7 @@ namespace Flavorly\InertiaFlash\Notification\Enums; -enum NotificationTypeEnum: string +enum NotificationKindEnum: string { case Toast = 'toast'; case Flash = 'flash'; diff --git a/src/Notification/FlashNotification.php b/src/Notification/FlashNotification.php index 63a5135..2c16ba3 100644 --- a/src/Notification/FlashNotification.php +++ b/src/Notification/FlashNotification.php @@ -5,8 +5,8 @@ use Flavorly\InertiaFlash\Notification\Concerns\HasContentBlocks; use Flavorly\InertiaFlash\Notification\Concerns\HasIcon; use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationActions; +use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationDataKind; use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationDataLevel; -use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationDataType; use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationDataViaChannel; use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationDispatcher; use Flavorly\InertiaFlash\Notification\Concerns\HasReadableNotifications; @@ -15,8 +15,8 @@ use Flavorly\InertiaFlash\Notification\Data\NotificationIconData; use Flavorly\InertiaFlash\Notification\Data\NotificationReadableData; use Flavorly\InertiaFlash\Notification\Data\NotificationTimestampsData; +use Flavorly\InertiaFlash\Notification\Enums\NotificationKindEnum; use Flavorly\InertiaFlash\Notification\Enums\NotificationLevelEnum; -use Flavorly\InertiaFlash\Notification\Enums\NotificationTypeEnum; use Illuminate\Notifications\DatabaseNotification; use Illuminate\Support\Collection; use Illuminate\Support\Str; @@ -27,8 +27,8 @@ class FlashNotification extends Data use HasContentBlocks; use HasIcon; use HasNotificationActions; + use HasNotificationDataKind; use HasNotificationDataLevel; - use HasNotificationDataType; use HasNotificationDataViaChannel; use HasNotificationDispatcher; use HasReadableNotifications; @@ -98,7 +98,7 @@ protected function ensureDefaults(): void // @phpstan-ignore-next-line $this->level(config('inertia-flash.notifications.defaults.level', NotificationLevelEnum::Info)); // @phpstan-ignore-next-line - $this->type(config('inertia-flash.notifications.defaults.type', NotificationTypeEnum::Flash)); + $this->kind(config('inertia-flash.notifications.defaults.kind', NotificationKindEnum::Flash)); } /** @@ -197,7 +197,7 @@ public static function fromModel(DatabaseNotification $notification): self $data->actions = NotificationActionData::collect($notification->data->get('actions', []), Collection::class); $data->icon = NotificationIconData::from($notification->data->get('icon', [])); $data->level = NotificationLevelEnum::tryFrom($notification->data->get('level', NotificationLevelEnum::Info)) ?? NotificationLevelEnum::Info; - $data->type = NotificationTypeEnum::tryFrom($notification->data->get('type', NotificationTypeEnum::Flash)) ?? NotificationTypeEnum::Flash; + $data->kind = NotificationKindEnum::tryFrom($notification->data->get('kind', NotificationKindEnum::Flash)) ?? NotificationKindEnum::Flash; $data->via = collect($notification->data->get('via', [])); $data->readable(); diff --git a/src/Notification/Notifications/DispatchableFlashNotification.php b/src/Notification/Notifications/DispatchableFlashNotification.php index ca6029e..68d3fdb 100644 --- a/src/Notification/Notifications/DispatchableFlashNotification.php +++ b/src/Notification/Notifications/DispatchableFlashNotification.php @@ -119,6 +119,11 @@ public function viaQueues(): array return config('inertia-flash.notifications.queues', []); } + public function broadcastAs(): string + { + return 'flash-notification'; + } + /** * Get the notification's database type. */