Lae/app/Notifications/WebChannel.php

41 lines
872 B
PHP
Raw Normal View History

<?php
namespace App\Notifications;
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.
*
* @param mixed $notifiable
* @param Notification $notification
*
* @return void
*/
public function send(mixed $notifiable, Notification $notification): void
{
$data = $notification->toArray($notifiable);
if (!$data) {
return;
}
$user_id = $notifiable->user_id ?? $notifiable->id;
$user = User::find($user_id);
if (!in_array($data['type'] ?? '', ['info', 'success', 'warning', 'error'])) {
2023-01-11 12:19:05 +00:00
$data['type'] = 'info';
}
broadcast(new Users($user, $data['type'], $data));
}
}