调用成员函数 getEmailForPasswordReset() on null


我不知道

为什么在尝试重置密码时出现此错误。

我有另一个具有相同代码的项目,它可以工作。
我注意到错误位于"资源/视图/身份验证/电子邮件/密码.php"文件中,该文件确实具有空$user变量。

奇怪的是,在调用视图的函数中,$user变量具有值。
当变量传递到视图时,它会丢失值。

public function emailResetLink(CanResetPasswordContract $user, $token, Closure $callback = null)
{
    // We will use the reminder view that was given to the broker to display the
    // password reminder e-mail. We'll pass a "token" variable into the views
    // so that it may be displayed for an user to click for password reset.
    $view = $this->emailView;
    **// HERE THE $user VARIABLE HAS VALUE.**
    **// IN THE $view VIEW THE $user VARIABLE IS NULL**
    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);
        }
    });
}

更新
这是用户模型:

<?php
namespace App;
use IlluminateFoundationAuthUser as Authenticatable;
use ZizacoEntrustTraitsEntrustUserTrait;
class User extends Authenticatable
{
    use EntrustUserTrait; // add this trait to your user model
    protected $fillable = [
        'name', 'email'
    ];
    protected $hidden = [
        'password',
    ];
}

知道了,
问题是我创建并忘记了ViewComposer。

这是作曲家服务提供商:

class ComposerServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        // Using class based composers...
        View::composer(
            '*', 'AppHttpViewComposersUserComposer'
        );
    }
    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

这是(编辑以使其工作(UserComposer类:

class UserComposer
{
    /**
     * constructor.
     */
    public function __construct()
    {
    }
    /**
     * Bind data to the view.
     *
     * @param  View  $view
     * @return void
     */
    public function compose(View $view)
    {
        $excludedViews = ['auth.emails.password'];
        if (!in_array($view->getName() , $excludedViews))
        {
            $view->with('user', session('user'));
        }
    }
}

使用"excludedViews"变量,我可以在所有路由中注入"user"变量,但重置密码除外。

相关内容

  • 没有找到相关文章