Skip to content

Commit

Permalink
Added missing code to set locale from model preferred locale (#45308)
Browse files Browse the repository at this point in the history
  • Loading branch information
clementbirkle authored Dec 15, 2022
1 parent 2427cec commit a670437
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Contracts\Queue\Factory as Queue;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -577,6 +578,10 @@ public function hasFrom($address, $name = null)
*/
public function to($address, $name = null)
{
if (! $this->locale && $address instanceof HasLocalePreference) {
$this->locale($address->preferredLocale());
}

return $this->setAddress($address, $name, 'to');
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Integration/Mail/SendingMailWithLocaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public function testLocaleIsSentWithModelPreferredLocale()
$this->assertStringContainsString('esm',
app('mailer')->getSymfonyTransport()->messages()[0]->toString()
);

$mailable = new Mailable;
$mailable->to($recipient);

$this->assertSame($recipient->email_locale, $mailable->locale);
}

public function testLocaleIsSentWithSelectedLocaleOverridingModelPreferredLocale()
Expand Down

0 comments on commit a670437

Please sign in to comment.