adding example for notification

This commit is contained in:
Geriano
2022-07-29 14:16:01 +07:00
parent 8ab313da50
commit c7ff791eb6
2 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class GreetingNotification extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['broadcast'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->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 [
//
];
}
}

View File

@@ -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)
})
</script>
<style>