首页 > 解决方案 > 如何解决对未定义方法 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 中发送邮件....

谢谢你提前帮助我..

标签: phplaravelemailnotifications

解决方案


推荐阅读