where('status', '!=', 'archived'); if ($slug = $this->option('slug')) { $query->where('slug', $slug); } $companies = $query->get(); $days = (int) $this->option('days'); $totalUpdated = 0; foreach ($companies as $company) { app(TenantManager::class)->setCurrent($company); $suppliers = Supplier::where('is_active', true)->get(); $changed = 0; foreach ($suppliers as $supplier) { $score = $analytics->computedRating($supplier, $days); if ($score !== null && $score !== (int) $supplier->rating) { $supplier->rating = $score; $supplier->saveQuietly(); $changed++; } } $this->info(sprintf('[%s] suppliers rated, %d updated', $company->slug, $changed)); $totalUpdated += $changed; } $this->info("Total suppliers updated: {$totalUpdated}"); return self::SUCCESS; } }