Using User Locale for Notifications
Mahmoud Ramadan

Mahmoud Ramadan @mmramadan496

About: Computer Science Geek 🧐 || Software Engineer 👨‍💻 || Digging Code Creator 🚀

Location:
Mansoura, Dakahlia, Egypt
Joined:
Jan 15, 2024

Using User Locale for Notifications

Publish Date: Jun 18 '25
0 1

It is considered best practice to send notifications and emails in the recipient's preferred locale. Laravel supports this out of the box through the HasLocalePreference contract, which enables you to easily define a user's locale preference:

use Illuminate\Contracts\Translation\HasLocalePreference;

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

Once you implement the HasLocalePreference contract, Laravel will automatically use the preferred locale returned by the preferredLocale method when sending notifications and emails.

Comments 1 total

  • Admin
    AdminJun 19, 2025

    We’re thrilled to announce free tokens now live for Dev.to contributors in recognition of your efforts on Dev.to! Don’t miss this opportunity here (wallet connection required). – Admin

Add comment