From c7ff791eb6c7221370b32ffbefabcd07982d0fbc Mon Sep 17 00:00:00 2001 From: Geriano Date: Fri, 29 Jul 2022 14:16:01 +0700 Subject: [PATCH] adding example for notification --- app/Notifications/GreetingNotification.php | 75 ++++++++++++++++++++++ resources/js/Layouts/DashboardLayout.vue | 6 ++ 2 files changed, 81 insertions(+) create mode 100644 app/Notifications/GreetingNotification.php diff --git a/app/Notifications/GreetingNotification.php b/app/Notifications/GreetingNotification.php new file mode 100644 index 0000000..92eab9c --- /dev/null +++ b/app/Notifications/GreetingNotification.php @@ -0,0 +1,75 @@ +line('The introduction to the notification.') + ->action('Notification Action', url('/')) + ->line('Thank you for using our application!'); + } + + /** + * Get the broadcast representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toBroadcast($notifiable) + { + return (new BroadcastMessage([ + 'name' => 'Test', + ])); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/resources/js/Layouts/DashboardLayout.vue b/resources/js/Layouts/DashboardLayout.vue index 19cf721..a05f6e7 100644 --- a/resources/js/Layouts/DashboardLayout.vue +++ b/resources/js/Layouts/DashboardLayout.vue @@ -13,6 +13,12 @@ const self = getCurrentInstance() const open = ref(window.innerWidth > 669) onMounted(() => window.addEventListener('resize', () => open.value = window.innerWidth > 669)) + +const { user } = usePage().props.value +Echo.private(`App.Models.User.${user.id}`) + .notification(notification => { + console.log(notification) + })