Skip to content

Commit a670437

Browse files
Added missing code to set locale from model preferred locale (#45308)
1 parent 2427cec commit a670437

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Illuminate/Mail/Mailable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Contracts\Queue\Factory as Queue;
1111
use Illuminate\Contracts\Support\Htmlable;
1212
use Illuminate\Contracts\Support\Renderable;
13+
use Illuminate\Contracts\Translation\HasLocalePreference;
1314
use Illuminate\Support\Collection;
1415
use Illuminate\Support\HtmlString;
1516
use Illuminate\Support\Str;
@@ -577,6 +578,10 @@ public function hasFrom($address, $name = null)
577578
*/
578579
public function to($address, $name = null)
579580
{
581+
if (! $this->locale && $address instanceof HasLocalePreference) {
582+
$this->locale($address->preferredLocale());
583+
}
584+
580585
return $this->setAddress($address, $name, 'to');
581586
}
582587

tests/Integration/Mail/SendingMailWithLocaleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public function testLocaleIsSentWithModelPreferredLocale()
9595
$this->assertStringContainsString('esm',
9696
app('mailer')->getSymfonyTransport()->messages()[0]->toString()
9797
);
98+
99+
$mailable = new Mailable;
100+
$mailable->to($recipient);
101+
102+
$this->assertSame($recipient->email_locale, $mailable->locale);
98103
}
99104

100105
public function testLocaleIsSentWithSelectedLocaleOverridingModelPreferredLocale()

0 commit comments

Comments
 (0)