public function generateUsername(FirstName $firstName, LastName $lastName, $offset = 1) { $fullNameStr = $firstName->toString() . $lastName->toString(); $modifier = $offset > 1 ? $offset : ''; $username = Username::fromNative(str_slug($fullNameStr . $modifier)); if ($this->userRepository->userOfUsername($username)) { return $this->generateUsername($firstName, $lastName, $offset + 1); } return $username; }
public static function create() { // return 'here'; $faker = Factory::create(); $identifier = UserId::generate(); $email = Email::fromNative($faker->email); $first = FirstName::fromNative($faker->word); $last = LastName::fromNative($faker->word); $username = Username::fromNative($faker->word); $password = HashedPassword::fromNative(str_random(10)); return User::create($identifier, $email, $first, $last, $username, $password); }
/** * Get the User's username * * @return string */ public function username() { return Username::fromNative($this->username); }