简体   繁体   中英

Laravel, How to reset password to email where duplicated in users table

I have the users table which contains information about users with their role, so the unique here is 'email', 'role_id','phone' combined together, so email can be duplicated but cant be duplicate if the role_id and phone number were duplicated, this because user can be customer which means role_id=1, or he has account as business account which means role_id=2 but what if this customer needs to reset his customer password, or his business account password? how can I do this?

table

    Schema::create('users', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->string('fname');
        $table->string('lname');
        $table->boolean('role_id')->default(1);
        $table->string('phone');
        $table->string('email');
        $table->unique(['email', 'role_id','phone']);
        $table->string('password');
        $table->boolean('status')->default(1);
        $table->rememberToken();
        $table->timestamp('email_verified_at')->nullable();
        $table->timestamps();
    });
  1. Good solution is to add a new relationship table, such as user_role (user_role.user_id, user_role.role_id) and create an index using one unique field (email OR phone).

But you need to add a drop-down list of roles in the login form or elsewhere. Or change the "palitic of access". For example, if user has customer-role and business-role, you give him access to all the features of both roles.

  1. Another solution is to add a drop-down list of roles to the password-reset form ...

  2. One more solution is reset password for all rows of user. In this way, user can change a role by email for login

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM