我正在与Laravel一起作为Vue项目的后端,因此必须修改验证电子邮件代码。重新发送电子邮件时,我现在遇到错误。
错误:"Access to undeclared static property: App\Notifications\VerifyEmail::$toMailCallback"
如果我删除if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable);
}
它发送电子邮件,但是出现当前代码错误。
namespace App\Notifications;
...
class VerifyEmail extends Notification
{
use Queueable;
...
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable);
}
return (new MailMessage)
->subject('Verify Email Address')
->line('Please click the button below to verify your email address.')
->action(
'Verify Email Address',
$this->verificationUrl($notifiable)
)
->line('If you did not create an account, no further action is required.');
}
/**
* Get the verification URL for the given notifiable.
*
* @param mixed $notifiable
* @return string
*/
protected function verificationUrl($notifiable)
{
$prefix = config('app.front_url') . config('app.email_verify_url');
$temporarySignedURL = URL::temporarySignedRoute(
'verification.verify', Carbon::now()->addMinutes(60), ['id' => $notifiable->getKey()]
);
// I use urlencode to pass a link to my frontend.
return $prefix . urlencode($temporarySignedURL);
}
/**
* Set a callback that should be used when building the notification mail message.
*
* @param \Closure $callback
* @return void
*/
public static function toMailUsing($callback)
{
static::$toMailCallback = $callback;
}
...
}
答案 0 :(得分:0)
花了几个小时试图找出答案,然后才发现我删除了一行代码...
public static $toMailCallback;
忘记声明它。解决了。