From 086dd241d2216adc2875cadfbc7974f97ac9753a Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Mon, 15 Apr 2024 21:20:36 +0200 Subject: [PATCH] Add user's locale preference --- app/Models/User.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index 6ae8655f..db4e1a9c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,6 +6,7 @@ use App\Models\Traits\WebAuthnManageCredentials; use Illuminate\Auth\Events\PasswordReset; use Illuminate\Auth\Notifications\ResetPassword; +use Illuminate\Contracts\Translation\HasLocalePreference; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; @@ -41,7 +42,7 @@ * @property-read \Illuminate\Database\Eloquent\Collection|\Laragear\WebAuthn\Models\WebAuthnCredential[] $webAuthnCredentials * @property-read int|null $web_authn_credentials_count */ -class User extends Authenticatable implements WebAuthnAuthenticatable +class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable { use AuthenticationLoggable; use HasApiTokens, HasFactory, Notifiable; @@ -86,6 +87,14 @@ class User extends Authenticatable implements WebAuthnAuthenticatable 'demoting', ]; + /** + * Get the user's preferred locale. + */ + public function preferredLocale() : string + { + return strval($this->preferences['lang']); + } + /** * Scope a query to only include admin users. *