<?php
use App\Modules\Vendor\Models\Vendor;
use Illuminate\Support\Facades\Broadcast;
/*
|--------------------------------------------------------------------------
| Broadcast Channel Routes — Phase 4
|--------------------------------------------------------------------------
| All private/presence channels must be authorized here.
| Public channels (prefixed with no auth) don't need entries.
*/
/**
* User notification channel.
* Each authenticated user listens on their own private channel.
*/
Broadcast::channel('App.Models.User.{id}', function ($user, int $id) {
return (int) $user->id === $id;
});
/**
* Per-vendor private channel.
* Used for new order alerts, payout notifications, stock alerts.
*/
Broadcast::channel('vendor.{vendorId}', function ($user, int $vendorId) {
$vendor = Vendor::find($vendorId);
return $vendor && $vendor->user_id === $user->id;
});
/**
* Admin-only broadcast channel.
* Used for platform-wide alerts, new vendor registrations, disputes.
*/
Broadcast::channel('admin', function ($user) {
return $user->hasRole(['SuperAdmin', 'Admin']);
});
/**
* Order tracking channel — accessible by order owner.
* UUID-based so it can't be guessed.
*/
Broadcast::channel('order.{uuid}', function ($user, string $uuid) {
return \App\Modules\Order\Models\Order::where('uuid', $uuid)
->where('user_id', $user->id)
->exists();
});