app/Services/AuthenticationService.php
/*
    * While there is a user in database with same username or the given username has length > 60 
    * we keep trying to generate another valid username
    **/
While there is a user in database with same username or the given username has length > 60
we keep trying to generate another valid username
While there is a user in database with same username or the given username has length > 60 we keep trying to generate another valid username
public function generateUsername($user, string $username): string
    {
        if ($user || strlen($username) > 60) {
            $defaultUsername = $username;
            while (!(!$user && strlen($username) <= 60)) {
                $maxLength = (int) 999999999999999999999999999999; 
                $randomNumber = mt_rand(1, $maxLength);
                $username = $defaultUsername . $randomNumber;
                $user = Users::where('username', $username)->withTrashed()->first();
            }
        }
        return $username;
    }
public function generateUsername ( $ user , string $ username ) : string { if ( $ user || strlen ( $ username ) > 60 ) { $ defaultUsername = $ username ; while ( ! ( ! $ user && strlen ( $ username ) <= 60 ) ) { $ maxLength = ( int ) 999999999999999999999999999999 ; $ randomNumber = mt_rand ( 1 , $ maxLength ) ; $ username = $ defaultUsername . $ randomNumber ; $ user = Users :: where ( 'username' , $ username ) -> withTrashed ( ) -> first ( ) ; } } return $ username ; }
While there is a user in database with same username or the given username has length > 60
 we keep trying to generate another valid username
While there is a user in database with same username or the given username has length > 60 we keep trying to generate another valid username
// 30 digits