Lae/app/Notifications/Channels/WebChannel.php

36 lines
745 B
PHP
Raw Normal View History

<?php
2023-01-13 14:11:56 +00:00
namespace App\Notifications\Channels;
use App\Events\Users;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
2023-01-11 12:19:05 +00:00
class WebChannel extends Notification
{
use Queueable;
/**
* Send the given notification.
*
2023-02-07 09:04:11 +00:00
* @param mixed $notifiable
* @param Notification $notification
* @return void
*/
public function send(mixed $notifiable, Notification $notification): void
{
$data = $notification->toArray($notifiable);
2023-02-07 09:04:11 +00:00
if (! $data) {
return;
}
$user_id = $notifiable->user_id ?? $notifiable->id;
2023-01-13 14:16:48 +00:00
$user = (new User)->find($user_id);
2023-01-13 14:11:56 +00:00
broadcast(new Users($user, $data['event'], $data));
}
}