Different name fields user table?

老子叫甜甜 提交于 2019-12-23 09:25:26

问题


I have a form with 2 fields (username, password) and a mysql table with those 2 same fields (username, password), and I authentication system working properly :)

But, I can not make it work if my table fields have different names, for example: (my_user, my_pass).

If you just change the username field on the other also works for me, that gives me problems is the password field.

My config auth.php

'driver' => 'eloquent'

Update

Already found the solution in my controller, the password name can not change.

Before (WRONG): What I've done in first place was wrong

$userdata = array(
        'my_user' => Input::get('my_user'),
        'my_pass' => Input::get('my_pass')
    );

it should be

$userdata = array(
        'my_user' => Input::get('my_user'),
        'password' => Input::get('my_pass')
    );

回答1:


You can define you own username and password field in the auth.php inside the config folder.

 return array(
    'driver' => 'eloquent',
    'username' => 'my_user',
    'password' => 'my_pass',
    'model' => 'User',
    'table' => 'users',
 );

I hope this can be of some help.




回答2:


I ran into this same problem. You need to extend your model:

// User.php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    protected $fillable = array('name','passwd','email','status','timezone','language','notify');
    protected $hidden = array('passwd');

    protected $table = "users_t";
    protected $primaryKey = "uid";

    public static $rules = array(
        'name' => 'required',
        'passwd' => 'required',
        'email' => 'required'
    );

    public function getAuthIdentifier() {
        return $this->getKey();
    }

    public function getAuthPassword() {
        return $this->passwd;
    }

    public function getReminderEmail() {
        return $this->email;
    }

    public static function validate($data) {
        return Validator::make($data,static::$rules);
    }
}



回答3:


You need to implements this methods too:

public function getRememberToken(){

}
public function setRememberToken($value){

}
public function getRememberTokenName(){

}


来源:https://stackoverflow.com/questions/17222734/different-name-fields-user-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!