$input * * @throws ValidationException */ public function create(array $input): User { Validator::make($input, [ 'name' => ['required', 'string', 'max:255'], 'email' => [ 'required', 'string', 'email', 'max:255', Rule::unique(User::class), // Never let public signup claim an existing (possibly not-yet- // provisioned) customer's email — ensureUser() would later link // that account and hand over the customer's portal. Rule::unique(Customer::class, 'email'), ], 'password' => $this->passwordRules(), ])->validate(); $user = User::create([ 'name' => $input['name'], 'email' => $input['email'], 'password' => Hash::make($input['password']), ]); // A public signup is a customer — create and link the record now so the // portal (Billing::purchase, Settings, …) has a customer to work with // before they buy a package. Customer::query()->create([ 'user_id' => $user->id, 'name' => $input['name'], 'email' => $input['email'], 'locale' => app()->getLocale(), 'status' => 'active', ]); return $user; } }