Skip to content

Commit dd1e0a6

Browse files
committed
set locale conditionally
1 parent 355b969 commit dd1e0a6

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/Illuminate/Mail/PendingMail.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,12 @@ public function later($delay, MailableContract $mailable)
175175
*/
176176
protected function fill(MailableContract $mailable)
177177
{
178-
return $mailable->to($this->to)
179-
->cc($this->cc)
180-
->bcc($this->bcc)
181-
->locale($this->locale);
178+
return tap($mailable->to($this->to)
179+
->cc($this->cc)
180+
->bcc($this->bcc), function ($mailable) {
181+
if ($this->locale) {
182+
$mailable->locale($this->locale);
183+
}
184+
});
182185
}
183186
}

tests/Integration/Mail/SendingMailWithLocaleTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ public function testMailIsSentWithSelectedLocale()
6969
);
7070
}
7171

72+
public function testMailIsSentWithLocaleFromMailable()
73+
{
74+
$mailable = new TestMail();
75+
$mailable->locale('ar');
76+
77+
Mail::to('[email protected]')->send($mailable);
78+
79+
$this->assertStringContainsString('esm',
80+
app('swift.transport')->messages()[0]->getBody()
81+
);
82+
}
83+
7284
public function testMailIsSentWithLocaleUpdatedListenersCalled()
7385
{
7486
Carbon::setTestNow('2018-04-01');

0 commit comments

Comments
 (0)