get(); foreach ($roles as $role) { $this->command->info("Restricting permissions for role: {$role->name} (ID: {$role->id}, Company: {$role->company_id})"); // Filter only permissions that actually exist in the database $validPermissions = Permission::whereIn('name', $employeePermissions)->pluck('name')->toArray(); // Sync permissions (this removes old ones and adds new ones) $role->syncPermissions($validPermissions); } $this->command->info('Done! All employee roles have been restricted.'); } }