From 88af12e386aee3f4879cc8aa57da83f4132a6b60 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Tue, 10 Jan 2023 20:46:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E5=BC=BA=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BB=A5=E5=8F=8A=E5=88=A0=E9=99=A4=20broadcast=20as?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Events/{UserEvent.php => Users.php} | 33 ++++++++----------------- 1 file changed, 10 insertions(+), 23 deletions(-) rename app/Events/{UserEvent.php => Users.php} (51%) diff --git a/app/Events/UserEvent.php b/app/Events/Users.php similarity index 51% rename from app/Events/UserEvent.php rename to app/Events/Users.php index 8883e18..63aba27 100644 --- a/app/Events/UserEvent.php +++ b/app/Events/Users.php @@ -2,40 +2,32 @@ namespace App\Events; +use App\Models\Module; +use App\Models\User; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Auth; -class UserEvent extends Event implements ShouldBroadcastNow +class Users extends Event implements ShouldBroadcastNow { use SerializesModels; - public $user_id; + public User $user; public string $type = 'ping'; - public $message; - public $module; + public string|array $message; + public null|Module $module; /** * Create a new event instance. * * @return void */ - public function __construct($user_id, $type, $message) + public function __construct(User $user, $type, $message) { - // - $this->user_id = $user_id; - + $this->user = $user; $this->type = $type; - - // if message is model - if (is_object($message)) { - $this->message = $message->toArray(); - } else { - $this->message = $message; - } - - // if (Auth::check()) { + $this->message = $message; if (Auth::guard('module')->check()) { $this->module = Auth::guard('module')->user(); @@ -46,11 +38,6 @@ public function __construct($user_id, $type, $message) public function broadcastOn(): PrivateChannel { - return new PrivateChannel('users.' . $this->user_id); - } - - public function broadcastAs(): string - { - return 'user'; + return new PrivateChannel('users.' . $this->user->id); } }