60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use Illuminate\Broadcasting\Channel;
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class SystemNotification implements ShouldBroadcast
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
public $message;
|
|
|
|
public $type;
|
|
|
|
public $title;
|
|
|
|
public $data;
|
|
|
|
/**
|
|
* Create a new event instance.
|
|
*
|
|
* @param string $type (success, error, warning, info)
|
|
*/
|
|
public function __construct(string $message, string $type = 'info', ?string $title = null)
|
|
{
|
|
$this->message = $message;
|
|
$this->type = $type;
|
|
$this->title = $title ?? 'System Notification';
|
|
$this->data = [
|
|
'message' => $this->message,
|
|
'type' => $this->type,
|
|
'title' => $this->title,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the channels the event should broadcast on.
|
|
*
|
|
* @return array<int, Channel>
|
|
*/
|
|
public function broadcastOn(): array
|
|
{
|
|
return [
|
|
new Channel('system-notifications'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* The event's broadcast name.
|
|
*/
|
|
public function broadcastAs(): string
|
|
{
|
|
return 'message.sent';
|
|
}
|
|
}
|