php - 如何解决对未定义方法 stdClass::notify() 的调用
问题描述
laravel notify() 未定义的方法。如何解决它..帮助我..
错误是:- 调用未定义的方法 stdClass::notify()
我的控制器代码在这里:
use Illuminate\Http\Request;
use \App\Notifications\ResetLink;
use Auth;
use App\User;
use DB;
use App\Password;
public function forgot(){
return view('forgot');
}
public function forgotPw(Request $request){
if($user = User::where('email',$request->email)->first()){
DB::table('password_resets')->insert([
'token' => $this->token(),
'email' => $user->email
]);
$pr = DB::table('password_resets')->where('email',$user->email)- >first();
$pr->notify(new ResetLink($pr));
request()->session()->flash('success', "Forgot Link Successfully Sent...");
return redirect('login');
} else {
request()->session()->flash('error', "Forgot Link Not Sent...");
return redirect('forgot');
}
}
我的通知代码在这里:
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
类 ResetLink 扩展通知 { 使用 Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
public $pr;
}
/**
* 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)
->line('Click the Button and Reset Password!')
->action('Password Reset', url('/reset'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
我试图持续 2 个小时,但没有在 mailtrap 中发送邮件....
谢谢你提前帮助我..
解决方案
推荐阅读
- image - ACF 古腾堡块中的预览图像
- javascript - Angular/PWA - 无法安装站点:页面无法离线工作
- javascript - 使用 js 在来自数据库的文本之前和之后添加 HTML 元素
- c++ - 分配内存 - 指针
- java - 在 JVM 中找不到命令,例如 adb
- python - Django添加字段以创建超级用户命令
- flutter - Flutter 本地通知每周重复通知
- node.js - 将 API 响应写入 .txt 文件
- python - Featuretools:使用 Pandas 'rolling' 生成滚动总和、平均值等,但以天为单位进行偏移
- python - 在 discord.py 中添加反应角色时出错