I updated to Laravel 5.6 and I want to use the new locale
method from a Mailable
class.
I created a mailable class with
php artisan make:mail Test --markdown="emails.test"
This is my blade file:
@component('mail::message')
@lang('list.test')
@endcomponent
If I send a mail
$test = new \App\Mail\Test();
$test->locale('de');
\Mail::to('[email protected]')->send($test);
Then the mail is not using my locale file from resources/lang/de/list.php
<?php
return [ 'test' => 'Dies ist ein Test'];
Why is that?
Use locale with Mail Facade.
$test = new \App\Mail\Test();
\Mail::to('[email protected]')->locale('de')->send($test);
Mail Facade and Mailable refers to different classes. for using locale()
with Mailable try this.
$test = new \App\Mail\Test();
$test->locale('de')->send();
Try passing the locale in to the constructor and setting then setting it in the build
function:
public $locale;
public function __construct(string $locale = 'de')
{
$this->locale = $locale;
}
public function build()
{
return $this->locale($this->locale)
->from('[email protected]')
->view('emails.example');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With