-
-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
In Version 6 and 7 there is an issue with assigned template variables in relation with the queue:work command.
Instead of queue:listen queue:work does not always boot Laravel so the existing Smarty Instance is kept.
Steps to reproduce
- Create two Mailables
- Create a simple smarty template where the variable is dumped
- Assign a variable only to the first mailable view
- Queue both Mails
Result in queue:listen: As expected, the variable gets only applied to the first mailable
Result in queue:work: The variable is dumped in both templates
Example files
App/Mail/TestMail1.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
class TestMail1 extends Mailable
{
use Queueable;
public function build()
{
$this->view('mail.test', [
'example' => 'assigned to first mailable'
]);
return $this;
}
}
App/Mail/TestMail2.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
class TestMail2 extends Mailable
{
use Queueable;
public function build()
{
// "example" is not applied here
$this->view('mail.test');
return $this;
}
}
templates/mail/test.tpl
<pre>{$example}</pre>
TestController.php
Mail::queue(new TestMail1());
Mail::queue(new TestMail2());
Required Changes
Smarty assignments have to be cleared on each Mailable.
In the current implementation, there is a risk that variables that are not overwritten by a second Mailable are erroneously transmitted in an email.
Notes
- Tested with Laravel 9 and 10.
- Smarty Caching
false
- Smarty Force Compile
true
- The test
$variable
is applied to all further mailables (even if the template file name differs) - This issue only occurs with Smarty templates, Blade templates are not affected
Metadata
Metadata
Assignees
Labels
No labels