private function findOrCreateUser(SocialiteUser $eve_user): User
    {

        // Check if this user already exists in the database.
        if ($existing = User::find($eve_user->character_id)) {

            // If the character_owner_hash has changed, it might be that
            // this character was transferred. We will still allow the login,
            // but the group memberships the character had will be removed.
            if ($existing->character_owner_hash !== $eve_user->character_owner_hash) {

                // Update the group_id for this user based on the current
                // session status. If there is a user already logged in,
                // simply associate the user with a new group id. If not,
                // a new group is generated and given to this user.
                $existing->group_id = auth()->check() ?
                    auth()->user()->group->id : Group::create()->id;

                // Update the new character_owner_hash
                $existing->character_owner_hash = $eve_user->character_owner_hash;
                $existing->save();
            }

            // Detect if the current session is already logged in. If
            // it is, update the group_id for the new login to the same
            // as the current session, thereby associating the characters.
            if (auth()->check()) {

                // Log the association update
                event('security.log', [
                    'Updating ' . $existing->name . ' to be part of ' . auth()->user()->name,
                    'authentication',
                ]);

                // Re-associate the group membership for the newly logged in user.
                $existing->group_id = auth()->user()->group->id;
                $existing->save();

                // Remove any orphan groups we could create during the attachment process
                Group::doesntHave('users')->delete();

            }

            return $existing;
        }

        // Log the new account creation
        event('security.log', [
            'Creating new account for ' . $eve_user->name, 'authentication',
        ]);

        // Detect if the current session is already logged in. If
        // it is, update the group_id for the new login to the same
        // as the current session, thereby associating the characters.
        if (auth()->check()) {

            // Log the association update
            event('security.log', [
                'Updating ' . $eve_user->name . ' to be part of ' . auth()->user()->name,
                'authentication',
            ]);
        }

        return User::forceCreate([  // Only because I don't want to set id as fillable
            'id'                   => $eve_user->character_id,
            'group_id'             => auth()->check() ?
                auth()->user()->group->id : Group::create()->id,
            'name'                 => $eve_user->name,
            'active'               => true,
            'character_owner_hash' => $eve_user->character_owner_hash,
        ]);
    }
private function findOrCreateUser(SocialiteUser $eve_user): User
    {

        // Check if this user already exists in the database.
        if ($existing = User::find($eve_user->character_id)) {

            // If the character_owner_hash has changed, it might be that
            // this character was transferred. We will still allow the login,
            // but the group memberships the character had will be removed.
            if ($existing->character_owner_hash !== $eve_user->character_owner_hash) {

                // Update the group_id for this user based on the current
                // session status. If there is a user already logged in,
                // simply associate the user with a new group id. If not,
                // a new group is generated and given to this user.
                $existing->group_id = auth()->check() ?
                    auth()->user()->group->id : Group::create()->id;

                // Update the new character_owner_hash
                $existing->character_owner_hash = $eve_user->character_owner_hash;
                $existing->save();
            }

            // Detect if the current session is already logged in. If
            // it is, update the group_id for the new login to the same
            // as the current session, thereby associating the characters.
            if (auth()->check()) {

                // Log the association update
                event('security.log', [
                    'Updating ' . $existing->name . ' to be part of ' . auth()->user()->name,
                    'authentication',
                ]);

                // Re-associate the group membership for the newly logged in user.
                $existing->group_id = auth()->user()->group->id;
                $existing->save();

                // Remove any orphan groups we could create during the attachment process
                Group::doesntHave('users')->delete();

            }

            return $existing;
        }

        // Log the new account creation
        event('security.log', [
            'Creating new account for ' . $eve_user->name, 'authentication',
        ]);

        // Detect if the current session is already logged in. If
        // it is, update the group_id for the new login to the same
        // as the current session, thereby associating the characters.
        if (auth()->check()) {

            // Log the association update
            event('security.log', [
                'Updating ' . $eve_user->name . ' to be part of ' . auth()->user()->name,
                'authentication',
            ]);
        }

        return User::forceCreate([  // Only because I don't want to set id as fillable
            'id'                   => $eve_user->character_id,
            'group_id'             => auth()->check() ?
                auth()->user()->group->id : Group::create()->id,
            'name'                 => $eve_user->name,
            'active'               => true,
            'character_owner_hash' => $eve_user->character_owner_hash,
        ]);
    }
private function findOrCreateUser ( SocialiteUser $ eve_user ) : User { // Check if this user already exists in the database. if ( $ existing = User :: find ( $ eve_user -> character_id ) ) { // If the character_owner_hash has changed, it might be that // this character was transferred. We will still allow the login, // but the group memberships the character had will be removed. if ( $ existing -> character_owner_hash !== $ eve_user -> character_owner_hash ) { // Update the group_id for this user based on the current // session status. If there is a user already logged in, // simply associate the user with a new group id. If not, // a new group is generated and given to this user. $ existing -> group_id = auth ( ) -> check ( ) ? auth ( ) -> user ( ) -> group -> id : Group :: create ( ) -> id ; // Update the new character_owner_hash $ existing -> character_owner_hash = $ eve_user -> character_owner_hash ; $ existing -> save ( ) ; } // Detect if the current session is already logged in. If // it is, update the group_id for the new login to the same // as the current session, thereby associating the characters. if ( auth ( ) -> check ( ) ) { // Log the association update event ( 'security.log' , [ 'Updating ' . $ existing -> name . ' to be part of ' . auth ( ) -> user ( ) -> name , 'authentication' , ] ) ; // Re-associate the group membership for the newly logged in user. $ existing -> group_id = auth ( ) -> user ( ) -> group -> id ; $ existing -> save ( ) ; // Remove any orphan groups we could create during the attachment process Group :: doesntHave ( 'users' ) -> delete ( ) ; } return $ existing ; } // Log the new account creation event ( 'security.log' , [ 'Creating new account for ' . $ eve_user -> name , 'authentication' , ] ) ; // Detect if the current session is already logged in. If // it is, update the group_id for the new login to the same // as the current session, thereby associating the characters. if ( auth ( ) -> check ( ) ) { // Log the association update event ( 'security.log' , [ 'Updating ' . $ eve_user -> name . ' to be part of ' . auth ( ) -> user ( ) -> name , 'authentication' , ] ) ; } return User :: forceCreate ( [ // Only because I don't want to set id as fillable 'id' => $ eve_user -> character_id , 'group_id' => auth ( ) -> check ( ) ? auth ( ) -> user ( ) -> group -> id : Group :: create ( ) -> id , 'name' => $ eve_user -> name , 'active' => true , 'character_owner_hash' => $ eve_user -> character_owner_hash , ] ) ; }
Check if a user exists in the database, else, create
and return the User object.

Group memberships are also managed here, ensuring that
characters are automatically 'linked' via a group. If
an existsing, logged in session is detected, the new login
will be associated with that sessions group. Otherwise,
a new group for this user will be created.

@param \Laravel\Socialite\Two\User $eve_user

@return \Seat\Web\Models\User
Check if a user exists in the database else create and return the User object .