Lae/app/Notifications/Channels/WebChannel.php

34 lines
694 B
PHP
Raw Permalink 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.
*/
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-03-01 14:30:31 +00:00
if ($user) {
2023-03-01 15:00:28 +00:00
broadcast(new Users($user, $data['event'] ?? 'notification', $data));
2023-03-01 14:30:31 +00:00
}
}
}