Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.4-重置密码更改“;电邮;柱_Php_Mysql_Laravel - Fatal编程技术网

Php Laravel 5.4-重置密码更改“;电邮;柱

Php Laravel 5.4-重置密码更改“;电邮;柱,php,mysql,laravel,Php,Mysql,Laravel,我正在使用不同版本的Laravel,并构建了一个使用Laravel 5.4的插件,不幸的是,它使用了一个引用Laravel 3sic的DB “用户”表中有一列标题为“用户电子邮件” 在重置密码时,我想将DB查询更改为对照“user_email”而不是“email”进行检查。由于我当前收到错误: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause' 它尝试运行的SQL查询是: SQL: s

我正在使用不同版本的Laravel,并构建了一个使用Laravel 5.4的插件,不幸的是,它使用了一个引用Laravel 3sic的DB

用户”表中有一列标题为“用户电子邮件

在重置密码时,我想将DB查询更改为对照“user_email”而不是“email”进行检查。由于我当前收到错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause'
它尝试运行的SQL查询是:

SQL: select * from `users` where `email` = user@user.co.uk limit 1
有没有办法改变这个以适应


谢谢

ResetPasswordController

 protected $username = 'user_email';

另外,为了登录,请添加
LoginController

将此方法添加到您的
LoginController

public function username()
{
    return 'user_email';
}

要正确自定义电子邮件列,您需要做一些更改,首先需要将该方法(getEmailForPasswordReset和routeNotificationFor)覆盖到模型用户:

public function getEmailForPasswordReset()
{
    return $this->email_user;
}

public function routeNotificationFor($driver)
{
    if (method_exists($this, $method = 'routeNotificationFor'.Str::studly($driver))) {
        return $this->{$method}();
    }

    switch ($driver) {
        case 'database':
            return $this->notifications();
        case 'mail':
            return $this->email_user;
        case 'nexmo':
            return $this->phone_number;
    }
}
并实施:

use Illuminate\Support\Str;
在ForgotPasswordController中,需要重写名为sendResetLinkEmail和validateEmail的方法:

public function sendResetLinkEmail(Request $request)
{
    $this->validateEmail($request);

    // We will send the password reset link to this user. Once we have attempted
    // to send the link, we will examine the response then see the message we
    // need to show to the user. Finally, we'll send out a proper response.
    $response = $this->broker()->sendResetLink(
        $request->only('email_user')
    );

    return $response == Password::RESET_LINK_SENT
                ? $this->sendResetLinkResponse($response)
                : $this->sendResetLinkFailedResponse($request, $response);
}

protected function validateEmail(Request $request)
{
    $this->validate($request, ['email_user' => 'required|email']);
}
之后,您需要重写PasswordBroker中的某些方法(validateNewPassword、validatePasswordWithDefaults、reset),但我们需要

  • 在App\Providers中创建了一个CustomPasswordResetServiceProvider,我在其中注册了一个CustomPasswordBrokerManager实例

    namespace App\Providers;
    use Illuminate\Support\ServiceProvider;
    use App\Services\CustomPasswordBrokerManager; 
    class CustomPasswordResetServiceProvider extends ServiceProvider{
        protected $defer = true;
    
        public function register()
        {
            $this->registerPasswordBrokerManager();
        }
    
        protected function registerPasswordBrokerManager()
        {
            $this->app->singleton('auth.password', function ($app) {
                return new CustomPasswordBrokerManager($app);
            });
        }
    
        public function provides()
        {
            return ['auth.password'];
        }
    }
    
  • config/app.php中注释掉了行:
    //照亮\Auth\Passwords\PasswordResetServiceProvider::class,

    并添加:
    App\Providers\CustomPasswordResetServiceProvider::class,

  • App\Services文件夹内部创建了一个CustomPasswordBrokerManager,并复制了位于以下位置的默认PasswordBrokerManager的上下文: 照亮\Auth\Passwords\PasswordBrokerManager.php
    然后修改函数resolve以返回我的CustomPasswordProvider类的实例

    protected function resolve($name)
    {
        $config = $this->getConfig($name);
        if (is_null($config)) {
            throw new InvalidArgumentException("Password resetter [{$name}] is not defined.");
        }
    
        return new CustomPasswordBroker(
            $this->createTokenRepository($config),
            $this->app['auth']->createUserProvider($config['provider'])
    );
    }
    
  • 最后,在App\Services文件夹中,我创建了一个CustomPasswordBroker类,该类扩展了默认的PasswordBroker,位于:
    照亮\Auth\Passwords\PasswordBroker并覆盖我需要的函数

    use Illuminate\Auth\Passwords\PasswordBroker as BasePasswordBroker;    
    
    class CustomPasswordBroker extends BasePasswordBroker    
    {    
    // override the method validateNewPassword, validatePasswordWithDefaults and reset, you can take from Illuminate\Auth\Passwords\PasswordBroker   
    
    }      
    
  • 不确定这是否是最好的实现


    问候:)

    您能显示您的查询吗?当然:SQL:从
    用户
    where
    电子邮件
    =xyz@something.co.uk限制1我签入的文件。
    email
    列是硬编码的。在@OrkhanAlikhanov中硬编码的是哪种方法?如果您使用的是stand 5.4用户模型和身份验证,您应该能够在您的用户模型中添加一个名为“getEmailForPasswordReset()”的函数。您好,这似乎不起作用。仍然在SQL错误中询问电子邮件。在Laravel 5.7中不适用于我,因此-1适用于此。如果您可以看到仅适用于Laravel 5.4而不适用于Laravel 5.7,请先查看所有帖子,然后提交并评分答案,无需任何感谢