feat(helper): add sanitizeIntegers function to normalize integer values in an array

This commit is contained in:
Yoga Pangestu 2025-10-16 20:43:30 +07:00
parent 0b9e118ce0
commit d622dba2f4

View File

@ -51,3 +51,18 @@ function generateReferralCode(string $username, int $unique): string
return Str::upper($prefix).$year.$unique;
}
}
if (! function_exists('sanitizeIntegers')) {
function sanitizeIntegers(array $data, array $integerKeys = []): array
{
foreach ($data as $key => $value) {
if (empty($integerKeys) || in_array($key, $integerKeys)) {
if ($value === '' || $value === null) {
$data[$key] = 0;
}
}
}
return $data;
}
}