diff --git a/app/Models/User.php b/app/Models/User.php index 7a979ddc0..b1c98901e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -421,6 +421,36 @@ final class User extends Authenticatable ); } + /** + * Get country flag emoji from country code. + * Converts 2-letter country code to Unicode regional indicator symbols. + */ + protected function countryFlag(): Attribute + { + return Attribute::make( + get: function (): ?string { + $countryCode = $this->getCountryFromIp()['countryCode'] ?? null; + + if (empty($countryCode) || strlen($countryCode) !== 2) { + return null; + } + + // Convert country code to regional indicator symbols (flag emoji) + // Each letter is converted to its regional indicator equivalent + // A = π¦ (U+1F1E6), B = π§ (U+1F1E7), etc. + $countryCode = strtoupper($countryCode); + $flag = ''; + + for ($i = 0; $i < 2; $i++) { + $char = ord($countryCode[$i]) - ord('A') + 0x1F1E6; + $flag .= mb_chr($char, 'UTF-8'); + } + + return $flag; + }, + ); + } + /** * Lookup country information from IP address using ip-api.com. * diff --git a/resources/views/admin/users/index.blade.php b/resources/views/admin/users/index.blade.php index 1abe00d81..5a4f6fa3d 100644 --- a/resources/views/admin/users/index.blade.php +++ b/resources/views/admin/users/index.blade.php @@ -266,7 +266,7 @@