Php 未定义变量:在拉维8中应通知
我想在用户提交其电子邮件地址以重置密码后发送自定义电子邮件。为此,我刚刚创建了一个名为ResetPassword的新通知文件,如下所示:Php 未定义变量:在拉维8中应通知,php,laravel,laravel-8,Php,Laravel,Laravel 8,我想在用户提交其电子邮件地址以重置密码后发送自定义电子邮件。为此,我刚刚创建了一个名为ResetPassword的新通知文件,如下所示: class ResetPassword扩展通知 { 公众$token; 公共静态$toMailCallback; 公共函数构造($token) { $this->token=$token; } 公共职能通过($notifiable) { 返回[邮件]; } 托梅尔的公共职能(应呈报) { if(静态::$toMailCallback){ 返回call_user
class ResetPassword扩展通知
{
公众$token;
公共静态$toMailCallback;
公共函数构造($token)
{
$this->token=$token;
}
公共职能通过($notifiable)
{
返回[邮件];
}
托梅尔的公共职能(应呈报)
{
if(静态::$toMailCallback){
返回call_user_func(静态:$toMailCallback,$notifiable,$this->token);
}
返回(新邮件)
->主题(“自定义网站名称”)
->行('正在向您发送自定义电子邮件以重置密码')
->操作(Lang::get('ResetPassword')、url(config('app.url').route('password.reset',['token'=>this->token','email'=>$notifiable->getEmailForPasswordReset()],false)))
->行(Lang::get('您有60分钟的时间重置密码',['count'=>config('auth.passwords.'.config('auth.defaults.passwords').'.expire')))
->行(Lang::get('如果您没有请求密码重置,则无需进一步操作');
}
公共静态函数toMailUsing($callback)
{
静态::$toMailCallback=$callback;
}
}
我还在User.php
模型中使用了这个:
use App\Notifications\ResetPassword as ResetPasswordNotification;
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
但不知怎的,我得到了这个错误:
错误异常
未定义变量:应通知
因此,如果您知道发生此错误的原因以及我如何修复它,请让我知道
谢谢
更新#1:
错误是指此行:
->action(Lang::get('ResetPassword'), url(config('app.url').route('password.reset', ['token' => $this->token, 'email' => $notifiable->getEmailForPasswordReset()], false)))
我刚刚将
->action(Lang::get('ResetPassword')、url(config('app.url').route('password.reset',['token'=>$this->token','email'=>$notifiable->getEmailForPasswordReset()],false))
更改为->action(Lang::get('ResetPassword')、$url)
,错误消失了 错误应该准确地告诉您错误发生的位置,这对于发现和修复错误至关重要。这是否回答了您的问题@GregSchmidt是的,很抱歉没有添加这一行,我刚刚更新了问题,请参阅UPDATE#1 plz。@GregSchmidt->操作(Lang::get('ResetPassword')、url(config('app.url').route('password.reset'、['token'=>$this->token',email'=>$notifiable->getEmailForPasswordReset()],false))
无论你在哪里有这一行代码,您尚未定义$notifiable
变量。它不在您最初展示的任何代码中,因此这里没有任何感兴趣或用途。这是一个非常普遍/一般性的错误,您可以在我上面包含的链接中获取有关该错误的信息。