whereNotNull('customer_email') ->where('customer_email', '<>', '') ->select(['customer_email', 'customer_name']) ->orderBy('customer_email') ->get() ->unique(fn (License $license) => strtolower(trim((string) $license->customer_email))); $missing = 0; $created = 0; foreach ($customers as $license) { $email = strtolower(trim((string) $license->customer_email)); if ($email === '') { continue; } if (User::query()->whereRaw('lower(email) = ?', [$email])->exists()) { continue; } $missing++; if ($this->option('dry-run')) { $this->line("MISSING {$email}"); continue; } if ($accounts->ensure($email, $license->customer_name, ! $this->option('no-email'))) { $created++; $this->info("CREATED {$email}"); } } if ($this->option('dry-run')) { $this->info("{$missing} account(s) would be created."); } else { $this->info("{$created} account(s) created."); } return self::SUCCESS; } }