尝试发送密码重置链接时,Laravel 5.7视图文件中的未定义变量令牌

时间:2018-10-23 09:01:55

标签: laravel-5.7

我已发出自定义通知,以发送密码重置链接,并且 邮件的自定义刀片,但我不知道如何将令牌变量传递到myPasswordNotification.blade

User.php

use App\Notifications\myPasswordResetNotification;

public function sendPasswordResetNotification($token)
{
    $this->notify(new myPasswordResetNotification($token));
}

myPasswordResetNotification.php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class myPasswordResetNotification extends Notification
{
use Queueable;
public $token;
/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct($token)
{
    $this->token = $token;
}

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return ['mail'];
}

/**
 * Get the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
   return   new(MailMessage)->markdown('notifications.users.myPasswordNotification');
}

}

myPasswordNotification.blade.php

@component('mail::button', ['url' => route('password.reset', $token)])

1 个答案:

答案 0 :(得分:0)

我将toMail函数更改为此,现在似乎可以正常工作。

public function toMail($notifiable)
{
    $url = route('password.reset',$this->token);
    return (new MailMessage)->markdown('notifications.users.myPasswordNotification',['url'=> $url]);
}

然后我将myPasswordNotification.blade.php更改为此。

@component('mail::button', ['url' => $url])