Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

fahdshaykh's avatar

how to validate multiple username for single user

hi, i am working on users module each user have multiple username and each username must be unique for everyone. i have two table one is users table and second is usernames, in usernames tables i am saving userid and username.

my quest is how to work on each user have multiple usernames validation in request or controller?

0 likes
5 replies
folium's avatar

@fahadsheikh303 try this way...

public function username()
{
        $field = (filter_var(request()->email, FILTER_VALIDATE_EMAIL) || !request()->email) ? 'email' : 'username';
        if($field != 'email')
            $field = is_numeric(request()->email) ? 'matricule' : 'username';
        request()->merge([$field => request()->email]);
        return $field;
}
fahdshaykh's avatar

@folium i think its not validating before insert into the database. i am just checking unique validation.

Please or to participate in this conversation.