argument('business_id'); $roleNames = [ 'ceo' => "CEO#{$businessId}", 'coo' => "COO#{$businessId}", 'cfo' => "CFO#{$businessId}", 'pmo' => "PMO#{$businessId}", 'board' => "Board#{$businessId}", ]; foreach ($roleNames as $key => $roleName) { $role = Role::where('name', $roleName)->where('business_id', $businessId)->first(); if (! $role) { $this->error("Role missing: {$roleName}. Run role matrix command first."); return self::FAILURE; } } $singleAssignments = ['ceo', 'coo', 'cfo', 'pmo']; foreach ($singleAssignments as $opt) { $id = $this->option($opt); if (empty($id)) { continue; } $user = User::where('business_id', $businessId)->where('id', (int) $id)->first(); if (! $user) { $this->warn("Skipping {$opt}: user #{$id} not found in business #{$businessId}"); continue; } $user->assignRole($roleNames[$opt]); $this->info(strtoupper($opt)." assigned to {$user->id} ({$user->username})"); } $boardIds = array_filter((array) $this->option('board'), fn ($v) => $v !== null && $v !== ''); foreach ($boardIds as $id) { $user = User::where('business_id', $businessId)->where('id', (int) $id)->first(); if (! $user) { $this->warn("Skipping board user #{$id}: not found."); continue; } $user->assignRole($roleNames['board']); $this->info("BOARD assigned to {$user->id} ({$user->username})"); } $this->info("Manual executive assignment completed for business #{$businessId}"); return self::SUCCESS; } }