小编sam*_*m12的帖子

将变量推送到laravel上的通知视图中

我正在从laravel 5.2迁移到5.3,并且当用户想要重置密码时我想发送自定义文本.我现在看到,laravel使用通知,并且默认的"主题"在laravel核心中是硬编码的.我已经有了这个视图(从5.2开始),通知可以使用自定义视图,所以我尝试了这个:

在User.php(模型)中

/**
     * Send the password reset notification.
     *
     * @param  string  $token
     * @return void
     */
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new SendLinkMailPasswordReset($token, $this->full_name));
    }
Run Code Online (Sandbox Code Playgroud)

我创建了我的通知"SendLinkMailPasswordReset",用于"覆盖"laravel one和这里的toMail()方法:

/**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->view('auth.emails.password')
                    ->with
                    (
                        [
                            'user'=> $this->full_name,
                            'token'=> $this->token,
                        ]
                    );
    }
Run Code Online (Sandbox Code Playgroud)

如果我这样做dd($this->full_name),它可以工作,但当我重置密码时,我得到了Undefined variable: user

我不知道是否with是正确的方法,或者我是否愿意做.有关信息,如果我在我的sendPasswordResetNotification

public function sendPasswordResetNotification($token)
    { 
        $to=$this->email; …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5.3

3
推荐指数
1
解决办法
3440
查看次数

标签 统计

laravel ×1

laravel-5.3 ×1

php ×1