Reputation: 5207
I have alert system which sends emails to users. How can I send email in language based on user preference.
In users table I have a column language
. It stores the users selected language ('en', 'de', etc...)
I send emails using this:
public function handle(){
...
Mail::send('emails.newSearchAlert', ['u' => $u, 'results' => $results],
function ($m) use ($u) {
$m->from('[email protected]', 'My company');
}
$m->to($u->email)->subject('Your search alert - ' . $u->search);
});
In my newSearchAlert
I do this:
@if(App::isLocale('de'))
<h3>Ihr Alert</h3>
@elseif(App::isLocale('en'))
<h3>Your campaign alert: </h3>
but it doesn't work. I always get emails in German language. How can I use language
column from the table.
PS I use this package for localization: https://github.com/mcamara/laravel-localization
Upvotes: 0
Views: 548
Reputation: 1879
You have to set your locale before sending the E-Mail with
App::setLocale($language);
where $language
is the language you load from your database
i think in your case it would be
App::setLocale($u->language);
Upvotes: 1