我正在尝试更新 Laravel 中的验证电子邮件通知。我试图在 AppServiceProvider 中生成验证链接,然后将链接传递给通知类,但后来它给了我一个错误,即“未定义属性 ::$view”。
应用服务提供商
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
VerifyEmail::toMailUsing(function ($notifiable) {
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(config('auth.verification.expire', 60)),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
)
return new EmailVerification($verificationUrl);
});
}
验证邮箱
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class EmailVerification extends Notification implements ShouldQueue
{
use Queueable;
public $verificationUrl;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($verificationUrl)
{
$this->verificationUrl = $verificationUrl;
}
/**
* 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)
{
$verificationUrl = $this->verificationUrl;
return (new MailMessage)
->subject('Please verify your email')
->markdown('emails.verification', ['url' => $verificationUrl]);
}
精慕HU