Level 63
What do you expect and how is working your code ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
My current codes below does not work as expected
<?php
namespace App\Events;
use App\Models\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class NewUserRegistered implements ShouldBroadcast
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
/**
* Create a new event instance.
*/
public function __construct(
public User $user,
) {
//
}
/**
* Get the channel the event should broadcast on.
*/
public function broadcastOn(): Channel
{
return new PrivateChannel('super_admin_notifications');
}
/**
* Get the data to broadcast.
*
* @return array<string, mixed>
*/
public function broadcastWith(): array
{
return [
'id' => $this->user->id,
'name' => $this->user->name,
'email' => $this->user->email,
];
}
}
<?php
namespace App\Listeners;
use App\Enums\UserRoles;
use App\Events\NewUserRegistered;
use App\Models\User;
use Exception;
use Filament\Events\Auth\Registered;
use Filament\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\HtmlString;
class SendNewUserNotification implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(Registered $event): void
{
$user = $event->getUser();
if ($user) {
try {
$superAdmins = User::role(UserRoles::SuperAdmin->value)->get();
foreach ($superAdmins as $superAdmin) {
Notification::make()
->info()
->title(__('New User Registered'))
->body(new HtmlString(__('A new user has been registered with the name <span class="text-sm font-semibold capitalize text-primary-600 dark:text-primary-400">:name</span>', ['name' => $user->name])))
->broadcast($superAdmins);
}
broadcast(new NewUserRegistered($user));
Log::info('New user registered', [
'user_id' => $user->id,
'email' => $user->email,
]);
} catch (Exception $e) {
Log::error('Error broadcasting new user notification', [
'error' => $e->getMessage(),
]);
}
}
}
}
<?php
use App\Enums\UserRoles;
use App\Models\User;
use Illuminate\Support\Facades\Broadcast;
Broadcast::channel('new-user-created', function (User $user) {
return $user->hasRole(UserRoles::SuperAdmin->value);
});
echo.js
import Echo from "laravel-echo";
import Pusher from "pusher-js";
window.Pusher = Pusher;
window.Echo = new Echo({
broadcaster: "reverb",
key: import.meta.env.VITE_REVERB_APP_KEY,
wsHost: import.meta.env.VITE_REVERB_HOST,
wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? "https") === "https",
enabledTransports: ["ws", "wss"],
});
window.Echo.private("super_admin_notifications").listen(
"NewUserRegistered",
(e) => {
console.log("New user registered:", e);
}
);
Please or to participate in this conversation.