Laravel通知重定向到新创建的项目

时间:2018-11-21 00:22:17

标签: laravel eloquent

我正在尝试拥有它,以便每当新医生注册后,它就会触发Laravel通知向我发送电子邮件。这是我当前的代码:

控制器

$doctor = new Doctor();
$doctor->practice_id = $request->practice;
$doctor->first_name = $request->first_name;
$doctor->last_name = $request->last_name;
$doctor->type = $request->type;
$doctor->npi = $request->npi;
$doctor->license = $request->license;
$doctor->dea = $request->dea;
$doctor->is_approved = 0;
$doctor->is_ffs = 0;
$doctor->ffs_id = null;
$doctor->save();

Notification::route('mail', 'admin@test.com')->notify(new NewDoctor($doctor));

NewDoctor通知

public function via($notifiable)
{
    return ['mail'];
}

public function toMail($notifiable)
{
    return (new MailMessage)
        ->greeting('Doctor Registered!')
        ->line('A new doctor has been submitted for approval.')
        ->action('View Doctor', route('doctors.show', [$this->doctor]));
}

这将返回以下错误:Undefined property: App\Notifications\NewDoctor::$doctor

我假设出于某种原因doctor id并未通过,但是我不知道该如何通过。

1 个答案:

答案 0 :(得分:1)

private $doctor;

public function __construct($doctor)
{
    $this->doctor = $doctor;

}

New Doctor通知类中声明一个构造函数,然后只有您才能使用$doctor变量。