option('email') ?: $this->ask('Email'); $name = $this->option('name') ?: $this->ask('Name', 'Administrator'); $password = $this->option('password') ?: $this->secret('Password'); $validator = Validator::make( ['email' => $email, 'name' => $name, 'password' => $password], [ 'email' => 'required|email|max:255', 'name' => 'required|string|max:255', 'password' => ['required', Password::min(12)], ], ); if ($validator->fails()) { foreach ($validator->errors()->all() as $error) { $this->error($error); } return self::FAILURE; } // An operator address that also belongs to a customer would block that // customer from ever getting a portal login. Checked directly against // `users`, not only `customers`: see Customer::emailTaken(). if (Customer::emailTaken($email)) { $this->error('That address already belongs to a customer.'); return self::FAILURE; } $operator = Operator::query()->firstOrNew(['email' => $email]); $existed = $operator->exists; $operator->fill([ 'name' => $name, 'password' => Hash::make($password), ])->save(); $operator->syncRoles(['Owner']); app(PermissionRegistrar::class)->forgetCachedPermissions(); $this->info($existed ? "Existing account {$email} promoted to Owner and password reset." : "Owner account {$email} created."); return self::SUCCESS; } }