I know, the question is very strange...
Scenario: I have a Job class that sends an email, but the content of this email is modified, since the template of the email is selected before being of dispatch.
I do not know if it's a truth, but apparently Laravel maintain a cache of content that he fired for the first time. Even by changing the value of the properties, Job sends exactly the same email.
If this is true, I would like to know how to use the same job class to send different emails or what would be the best alternative.
\app\Jobs\SenderEmail001.php
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($template_id, $subject)
{
$this->template_id = $template_id;
$this->subject = $subject;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$template = Template::findOrFail($this->template_id);
\Mail::send([], [], function($message) use ($template)
{
$message
->replyTo('source@domain.com', 'Email Source')
->from('source@domain.com', 'Email Source')
->to('target@domain.com', 'Email Target')
->subject($this->subject)
->setBody($template->markup, 'text/html');
});
}
MyController
\App\Jobs\SenderEmail001::dispatch(6, 'subject subject subject')
->delay(now()->addSecond(100))
->onQueue('default');