我创建了一些需要使用课程变量来填充降价模板中某些数据的可邮物:
class CourseVisible extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
/**
* The course instance.
*
* @var Course
*/
public $course;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Course $course)
{
$course->load(['award:id,name']);
$this->course = $course;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('emails.course.visible');
}
}
我用以下路线对此进行了测试:
$course = Prospectus\Models\Course::find(13889);
Route::get('/course-visible', function () use ($course) {
return new Prospectus\Mail\CourseVisible($course);
});
一切都像魅力一样但是!
当我在我的实际代码中调用它时:
$course->visible = ($course->visible == true ? false : true);
$course->save();
Mail::to($course->notifiableUsers())->send(new CourseVisible($course));
观点:
# The {{ $course->award->name }} {{ $course->title }} ({{ $course->year }}) course has been published to the website.
我得到一个失败的工作和可怕的“ErrorException:Undefined variable:course”消息......
如果这有帮助,这是来自Horizon的数据:
{
"mailable": {
"course": {
"class": "Prospectus\\Models\\Course",
"id": 13889,
"connection": "mysql"
},
"from": [],
"to": [
{
"name": "XXXXXXXX",
"address": "XXXXXXXXX"
}
],
"cc": [],
"bcc": [],
"replyTo": [],
"subject": null,
"markdown": null,
"view": null,
"textView": null,
"viewData": [],
"attachments": [],
"rawAttachments": [],
"callbacks": [],
"connection": null,
"queue": null,
"chainConnection": null,
"chainQueue": null,
"delay": null,
"chained": []
},
"tries": null,
"timeout": null
}
如果相关,则应用程序,地平线和管理程序脚本位于与redis服务器和MySQL服务器不同的服务器上。
任何人都可以对此有所了解吗?谢谢!