2023-01-10 18:01:13 +00:00
|
|
|
<?php
|
|
|
|
|
2023-01-13 14:11:56 +00:00
|
|
|
namespace App\Notifications\Channels;
|
2023-01-10 18:01:13 +00:00
|
|
|
|
|
|
|
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
|
2023-01-10 18:01:13 +00:00
|
|
|
{
|
|
|
|
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) {
|
2023-01-10 18:01:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user_id = $notifiable->user_id ?? $notifiable->id;
|
|
|
|
|
2023-01-13 14:16:48 +00:00
|
|
|
$user = (new User)->find($user_id);
|
2023-01-10 18:01:13 +00:00
|
|
|
|
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
|
|
|
}
|
2023-01-10 18:01:13 +00:00
|
|
|
}
|
|
|
|
}
|