| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/client-portal-laravel/backup/routes/ |
Upload File : |
<?php
declare(strict_types=1);
use App\Models\Client;
use App\Models\Invoice;
use App\Models\Project;
use App\Models\Timesheet;
use App\Models\User;
use Illuminate\Support\Facades\Broadcast;
/*
|--------------------------------------------------------------------------
| Broadcast Channels
|--------------------------------------------------------------------------
|
| Here you may register all of the event broadcasting channels that your
| application supports. The given channel authorization callbacks are
| used to check if an authenticated user can listen to the channel.
|
*/
// Private user channel for notifications
Broadcast::channel('App.Models.User.{id}', function (User $user, int $id) {
return $user->id === $id;
});
// Private channel for client-specific updates
Broadcast::channel('client.{clientId}', function (User $user, int $clientId) {
// Admins can access all client channels
if ($user->isAdmin()) {
return true;
}
// Client users can only access their client's channel
return $user->clients()->where('clients.id', $clientId)->exists();
});
// Private channel for project updates
Broadcast::channel('project.{projectId}', function (User $user, int $projectId) {
$project = Project::find($projectId);
if (! $project) {
return false;
}
if ($user->isAdmin()) {
return true;
}
return $user->clients()->where('clients.id', $project->client_id)->exists();
});
// Admin-only channel for dashboard updates
Broadcast::channel('admin.dashboard', function (User $user) {
return $user->isAdmin();
});
// Presence channel for online users
Broadcast::channel('presence.online', function (User $user) {
return [
'id' => $user->id,
'name' => $user->name,
'role' => $user->role,
];
});
// Presence channel for project collaboration
Broadcast::channel('presence.project.{projectId}', function (User $user, int $projectId) {
$project = Project::find($projectId);
if (! $project) {
return false;
}
$hasAccess = $user->isAdmin() ||
$user->clients()->where('clients.id', $project->client_id)->exists();
if ($hasAccess) {
return [
'id' => $user->id,
'name' => $user->name,
'avatar' => $user->avatar_url ?? null,
'role' => $user->role,
];
}
return false;
});
// Invoice-specific channel
Broadcast::channel('invoice.{invoiceId}', function (User $user, int $invoiceId) {
$invoice = Invoice::find($invoiceId);
if (! $invoice) {
return false;
}
if ($user->isAdmin()) {
return true;
}
return $user->clients()->where('clients.id', $invoice->client_id)->exists();
});
// Admin-only channel for all admin updates
Broadcast::channel('admin', function (User $user) {
return $user->isAdmin();
});
// Timer channel for cross-device sync
Broadcast::channel('timer.{userId}', function (User $user, int $userId) {
return $user->id === $userId;
});
// Timesheet channel
Broadcast::channel('timesheet.{timesheetId}', function (User $user, int $timesheetId) {
$timesheet = Timesheet::find($timesheetId);
if (! $timesheet) {
return false;
}
// Owner can access their own timesheet
if ($user->id === $timesheet->user_id) {
return true;
}
// Admins can access all timesheets
return $user->isAdmin();
});
// Workflow channel for execution updates
Broadcast::channel('workflow.{workflowId}', function (User $user, int $workflowId) {
// Only admins can subscribe to workflow channels
return $user->isAdmin();
});
// Presence channel for client collaboration
Broadcast::channel('presence.client.{clientId}', function (User $user, int $clientId) {
$hasAccess = $user->isAdmin() ||
$user->clients()->where('clients.id', $clientId)->exists();
if ($hasAccess) {
return [
'id' => $user->id,
'name' => $user->name,
'avatar' => $user->avatar_url ?? null,
'role' => $user->role,
];
}
return false;
});