Lae/app/Events/Users.php

55 lines
1.1 KiB
PHP
Raw Normal View History

2022-09-22 04:18:35 +00:00
<?php
namespace App\Events;
use App\Models\Module;
use App\Models\User;
use Carbon\Carbon;
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
class Users extends Event implements ShouldBroadcastNow
2022-09-22 04:18:35 +00:00
{
use SerializesModels;
public User $user;
2022-09-22 06:00:03 +00:00
public string $type = 'ping';
public array $data;
public null|Module $module;
2022-09-22 04:18:35 +00:00
public Carbon $sent_at;
2022-09-22 04:18:35 +00:00
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(User $user, $type, array $data)
2022-09-22 04:18:35 +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
$this->sent_at = Carbon::now();
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
{
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
}