2022-09-22 04:18:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Events;
|
|
|
|
|
2023-01-10 12:46:23 +00:00
|
|
|
use App\Models\Module;
|
|
|
|
use App\Models\User;
|
2022-09-22 04:18:35 +00:00
|
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
|
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
2022-11-06 11:28:22 +00:00
|
|
|
use Illuminate\Queue\SerializesModels;
|
2022-09-22 06:00:03 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2022-09-22 04:18:35 +00:00
|
|
|
|
2023-01-10 12:46:23 +00:00
|
|
|
class Users extends Event implements ShouldBroadcastNow
|
2022-09-22 04:18:35 +00:00
|
|
|
{
|
|
|
|
use SerializesModels;
|
|
|
|
|
2023-01-10 12:46:23 +00:00
|
|
|
public User $user;
|
2022-09-22 06:00:03 +00:00
|
|
|
public string $type = 'ping';
|
2023-01-10 16:14:32 +00:00
|
|
|
public string|array $data;
|
2023-01-10 12:46:23 +00:00
|
|
|
public null|Module $module;
|
2022-09-22 04:18:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new event instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2023-01-10 16:22:09 +00:00
|
|
|
public function __construct(User $user, $type, string|array $data)
|
2022-09-22 04:18:35 +00:00
|
|
|
{
|
2023-01-10 12:46:23 +00:00
|
|
|
$this->user = $user;
|
2022-09-22 06:00:03 +00:00
|
|
|
$this->type = $type;
|
2023-01-10 16:22:09 +00:00
|
|
|
$this->data = $data;
|
2022-09-22 06:00:03 +00:00
|
|
|
|
2022-11-06 14:57:01 +00:00
|
|
|
if (Auth::guard('module')->check()) {
|
|
|
|
$this->module = Auth::guard('module')->user();
|
2022-09-22 06:00:03 +00:00
|
|
|
} else {
|
|
|
|
$this->module = null;
|
|
|
|
}
|
2022-09-22 04:18:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-11 11:33:34 +00:00
|
|
|
public function broadcastOn(): PrivateChannel
|
2022-09-22 04:18:35 +00:00
|
|
|
{
|
2023-01-10 12:46:23 +00:00
|
|
|
return new PrivateChannel('users.' . $this->user->id);
|
2022-09-22 04:18:35 +00:00
|
|
|
}
|
2023-01-10 15:01:25 +00:00
|
|
|
|
|
|
|
public function broadcastAs(): string
|
|
|
|
{
|
|
|
|
return 'common';
|
|
|
|
}
|
2022-09-22 04:18:35 +00:00
|
|
|
}
|