USING USER LOCALE FOR NOTIFICATIONS

Jun 16, 2025

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;
    }
}

 

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


AI Assistant

Choose AI provider

Text Tools

Make content clear and easy to read

Ask a Question

Get clear answers based on this content

0/500
Mahmoud Ramadan

Mahmoud Ramadan

Mahmoud is the creator of Digging Code and a contributor to Laravel since 2020.