Igor Simic
10 months ago

Laravel - change mail notification locale


How to send Laravel notification mail on different languages? Find out in this tutorial.

The goal is to send all mail notifications on user preferred language stored in User mode.
Laravel offering easy solution for this problem, all you need to do is extend User model or any other where you want to send notifications and add this code:
use Illuminate\Contracts\Translation\HasLocalePreference;

class User extends Model implements HasLocalePreference{
    /**
     * Get the user's preferred locale.
     *
     * @return string
     */
    public function preferredLocale()
    {
        return $this->locale;
    }
}

Automatically user locale will be passed to mail notification, it will switch the applications language, send the mail and change app lang back.

More detail instructions you can find here:
https://floyk.com/en/post/how-to-change-language-for-laravel-email-notifications