feat(helper): add sanitizeIntegers function to normalize integer values in an array
This commit is contained in:
parent
0b9e118ce0
commit
d622dba2f4
@ -51,3 +51,18 @@ function generateReferralCode(string $username, int $unique): string
|
|||||||
return Str::upper($prefix).$year.$unique;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user