Laravel使用不同的列名重置密码 [英] Laravel Reset Password Using Different Column Name

查看:58
本文介绍了Laravel使用不同的列名重置密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当涉及到具有不同列名称(用户名,电子邮件或密码)的授权时,我设法使其正常工作.

i managed to make it work when it comes to authorisation with different columns name either username, email or password.

但是密码提示似乎不起作用.

however the password reminder seems doesnt work.

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

i have changed the user model, to my table column name.

用户模型:

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())

Reminder Controller // Error: Column email not found (Not sure, its not reading the user model 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官方似乎没有提供适当的文档来实现自定义名称字段.

Took me hours to figure it out. Laravel official doesnt seems give a proper documentation to implement the custom name field.

我们只需要将输入字段名称更改为与表列名称相同.

We just need to change the input field name the same with your table column name.

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

这篇关于Laravel使用不同的列名重置密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆