Laravel 5验证:调用一个成员函数getEmailForPasswordReset()上的空 [英] Laravel 5 Authentication: Call to a member function getEmailForPasswordReset() on null

查看:495
本文介绍了Laravel 5验证:调用一个成员函数getEmailForPasswordReset()上的空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用包含laravel 5.2认证

I'm using the authentication included with laravel 5.2

我在重置密码形式的问题。

I have a problem at reset password form.

当我提交的电子邮件,它返回这个错误:

When I submit email, it returns this error:

这是空调用一个成员函数getEmailForPasswordReset()

Call to a member function getEmailForPasswordReset() on null

我发现这个原因由以下code:

I found this cause by the following code:

$user->getEmailForPasswordReset()

$用户

另外,我试图改变照亮\\验证\\密码\\ PasswordBroker 在函数 emailResetLink

In addition, I try to change Illuminate\Auth\Passwords\PasswordBroker at function emailResetLink

return $this->mailer->send($view, compact('token', 'user'), function ($m) use ($user, $token, $callback) {
        $m->to($user->getEmailForPasswordReset());

        if (! is_null($callback)) {
            call_user_func($callback, $m, $user, $token);
        }
    });

我改变:紧凑型('令牌','用户') - > ['令牌'=> $令牌,用户2'=> $ USER]

I change: compact('token', 'user') -> ['token'=>$token, 'user2'=>$user]

$用户自> getEmailForPasswordReset() - > $ user2-> getEmailForPasswordReset()

它工作得很好!

你能不能帮我找出我做错了什么?
谢谢你。

Can you help me figure out what I did wrong? Thanks.

推荐答案

这个问题绝对不是laravel文件,因此停止寻找那里与code搞乱,因为你可能打破更多的东西比你将修复和同时一旦你做作曲家更新将被覆盖。

The problem is definitely not in laravel files, so stop looking there and messing with the code, because you risk breaking more stuff than you will fix and also it will be overwritten once you do composer update.

在$用户为空,因为系统无法找到您要发送密码重置链接给用户。这将是更有益的,看看你的控制器,实现了密码重置(提交)。 Laravel自带pretty很好的起点,你不应该overengineer它,除非需要: HTTPS ://laravel.com/docs/5.2/authentication#resetting-routing

The $user is null because the system cannot find the user you want to send a password reset link to. It would be more helpful to see your controller that implements the password resetting (submitting). Laravel comes with a pretty good starting point and you should not overengineer it unless needed: https://laravel.com/docs/5.2/authentication#resetting-routing

因此​​,对于发送重置链接的方法看起来是这样的:

So the method for sending reset links would look something like this:

public function postEmail(Request $request)
    {
        $this->validate($request, ['email' => 'required|email']);

        $response = Password::sendResetLink($request->only('email'), function (Message $message) {
            $message->subject($this->getEmailSubject());
        });

        switch ($response) {
            case Password::RESET_LINK_SENT:
                return redirect()->back()->with('message', 'Password reset link sent');

            case Password::INVALID_USER:
                return redirect()->back()->with('message', 'User not found');
        }
    }

正如你看到有参与为您办理任何用户对象。

As you see there's no User objects involved for you to handle.

这篇关于Laravel 5验证:调用一个成员函数getEmailForPasswordReset()上的空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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