Laravel使用不同的列名称重置密码


Laravel Reset Password Using Different Column Name

当涉及到使用不同列名称的用户名、电子邮件或密码进行授权时,我设法使其工作。

如何更改/Laravel 4和Laravel 5用户身份验证的自定义密码字段名称

但是密码提醒似乎不起作用。

我已经将用户模型更改为我的表列名称。

用户型号:

use Illuminate'Auth'UserTrait;
use Illuminate'Auth'UserInterface;
use Illuminate'Auth'Reminders'RemindableTrait;
use Illuminate'Auth'Reminders'RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
    use UserTrait, RemindableTrait;
    protected $primaryKey = 'user_id';
    protected $table = 'user';
    public function getReminderEmail() {
        return $this->user_email;
    }
    public function getAuthPassword() {
        return $this->user_pwd;
    }
    public function getRememberTokenName() {
        return 'user_token';
    }
}

用户控制器

Auth::attempt(  array(
 'user_name'    => $username, 
 'password'     => $password
), TRUE );

提醒控制器//错误:找不到列电子邮件(不确定,它没有读取用户模型getReminderEmail())

public function post_reminder() {
        switch ($response = Password::remind(Input::only('email'))) {
            case Password::INVALID_USER:
                return Redirect::back()->with('error', Lang::get($response));
            case Password::REMINDER_SENT:
                return Redirect::back()->with('status', Lang::get($response));
        }

}
花了

我几个小时才弄清楚。Laravel官方似乎没有提供适当的文档来实现自定义名称字段。

我们只需要更改输入字段名称,使其与表列名称相同。

Field could be anything
<input type="email" name="user_email">
我认为

我们可以添加自定义字段,以下是我想出的添加自定义字段的步骤。

1 - 在寄存器视图中添加input字段。

i.e. <input type="email" name="you_custome_field">

2 - 打开应用程序/服务/注册器.php并在创建函数中注册自定义 fied。

public function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'you_custome_field' => $data['you_custome_field'],
        ]);
    }

3 -(可选)打开user model应用程序/用户.php根据需要将字段注册为guardedfillable

我希望这会奏效。