whereNotNull('customer_email') ->where('customer_email', '!=', '') ->orderBy('id') ->get(['customer_email', 'customer_name']) ->unique(fn (License $license) => strtolower(trim((string) $license->customer_email))); $created = 0; foreach ($customers as $license) { $email = strtolower(trim((string) $license->customer_email)); $exists = \App\Models\User::whereRaw('lower(email) = ?', [$email])->exists(); if ($exists) { continue; } if ($this->option('dry-run')) { $this->line("Missing account: {$email}"); $created++; continue; } $user = $accounts->ensure($email, $license->customer_name); if ($user) { $this->info("Created account: {$email}"); $created++; } } $this->newLine(); $this->info($this->option('dry-run') ? "{$created} customer account(s) need creating." : "{$created} customer account(s) created."); return self::SUCCESS; } }