Php Laravel 5.4-重置密码更改“;电邮;柱
我正在使用不同版本的Laravel,并构建了一个使用Laravel 5.4的插件,不幸的是,它使用了一个引用Laravel 3sic的DB “用户”表中有一列标题为“用户电子邮件” 在重置密码时,我想将DB查询更改为对照“user_email”而不是“email”进行检查。由于我当前收到错误: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
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),但我们需要
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'];
}
}
//照亮\Auth\Passwords\PasswordResetServiceProvider::class,
并添加:
App\Providers\CustomPasswordResetServiceProvider::class,
然后修改函数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'])
);
}
照亮\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,请先查看所有帖子,然后提交并评分答案,无需任何感谢