@php
$authUser = auth()->user();
$maskedName = old('fullName');
$maskedMobile = old('mobileNumber');
$maskedEmail = old('emailId');
if ($authUser) {
$fullName = trim((string) ($authUser->name ?? ''));
$mobile = !empty($authUser->phone)
? preg_replace('/\D+/', '', (string) aes_decrypt($authUser->phone))
: '';
$email = !empty($authUser->email)
? trim((string) aes_decrypt($authUser->email))
: '';
$maskedName = preg_replace_callback('/[A-Za-z]+/', function ($matches) {
$part = $matches[0];
if (strlen($part) <= 2) {
return $part;
}
return substr($part, 0, 2) . str_repeat('*', strlen($part) - 2);
}, $fullName);
$maskedMobile = $mobile !== ''
? (strlen($mobile) <= 4
? str_repeat('*', strlen($mobile))
: str_repeat('*', strlen($mobile) - 4) . substr($mobile, -4))
: '';
if ($email !== '' && str_contains($email, '@')) {
[$localPart, $domainPart] = explode('@', $email, 2);
$visible = substr($localPart, 0, min(2, strlen($localPart)));
$maskedEmail = $visible . str_repeat('*', max(strlen($localPart) - strlen($visible), 1)) . '@' . $domainPart;
} else {
$maskedEmail = '';
}
}
@endphp