From 7bd841a53d40dca4fbe0ed54a0c8fd10321b4532 Mon Sep 17 00:00:00 2001 From: ljx Date: Thu, 23 May 2024 03:22:27 +0000 Subject: [PATCH] fix number cast when post empty string --- src/Casting/FloatCast.php | 2 +- src/Casting/IntegerCast.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Casting/FloatCast.php b/src/Casting/FloatCast.php index f0a7a75..5111806 100644 --- a/src/Casting/FloatCast.php +++ b/src/Casting/FloatCast.php @@ -13,7 +13,7 @@ final class FloatCast implements Castable */ public function cast(string $property, mixed $value): float { - if (! is_numeric($value)) { + if (! is_numeric($value) && $value !== '') { throw new CastException($property); } diff --git a/src/Casting/IntegerCast.php b/src/Casting/IntegerCast.php index a834bc4..5c2cdf5 100644 --- a/src/Casting/IntegerCast.php +++ b/src/Casting/IntegerCast.php @@ -13,7 +13,7 @@ final class IntegerCast implements Castable */ public function cast(string $property, mixed $value): int { - if (! is_numeric($value)) { + if (! is_numeric($value) && $value !== '') { throw new CastException($property); }