我正在尝试拥有它,以便每当新医生注册后,它就会触发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
并未通过,但是我不知道该如何通过。
答案 0 :(得分:1)
private $doctor;
public function __construct($doctor)
{
$this->doctor = $doctor;
}
在New Doctor
通知类中声明一个构造函数,然后只有您才能使用$doctor
变量。