【发布时间】:2020-07-12 06:00:23
【问题描述】:
请我尝试自定义 Laravel 验证电子邮件
在我的用户模型中,我有这个
public function sendEmailVerificationNotification()
{
$this->notify(new MyNotification);
}
然后我跑了
php artisan make:notification MyNotification
里面有这个
<?php
namespace App\Notifications;
use Auth;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\URL;
class MyNotification extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* 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)
->subject('Verify Email Address')
//I am trying output Hello User Name
->greeting('Hello!' {Auth::user()->name} )
->line('The introduction to the notification.')
->line('Please click the button below to verify your email address.')
->action(Lang::get('Verify Email Address'), $verificationUrl)
->line('If you did not create an account, no further action is required.')
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
这个
greeting('Hello!' {Auth::user()->name}
返回错误
非法字符串偏移 'John Doe'
这个
action(Lang::get('验证电子邮件地址'), $verificationUrl)
返回错误
未定义变量:verificationUrl
然后我添加了这个,
$verificationUrl = $this->verificationUrl($notifiable);
返回新错误
调用未定义的方法 App\Notifications\MyNotification::verificationUrl()
我现在真的不知道该怎么办。
【问题讨论】:
标签: laravel