From 3682ce4bd21dacf9d215fce565087ff6b4851bcf Mon Sep 17 00:00:00 2001 From: Samgu Lee Date: Tue, 7 Jan 2025 14:57:03 +0900 Subject: [PATCH] Fix a decimal error in models (#102) --- src/Resolvers/DecimalResolver.php | 6 +++++- tests/Unit/Resolvers/DecimalResolverTest.php | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Resolvers/DecimalResolver.php b/src/Resolvers/DecimalResolver.php index 90655d5..1a84d47 100644 --- a/src/Resolvers/DecimalResolver.php +++ b/src/Resolvers/DecimalResolver.php @@ -49,6 +49,10 @@ public function nova(): ?string public function cast(): ?string { - return 'decimal:'.Bracket::of($this->column->bracket)->escape(); + if (empty($this->column->bracket)) { + return null; + } + + return 'decimal:'.trim(preg_replace('/.+,/', '', $this->column->bracket)); } } diff --git a/tests/Unit/Resolvers/DecimalResolverTest.php b/tests/Unit/Resolvers/DecimalResolverTest.php index 5e49e76..e0fba14 100644 --- a/tests/Unit/Resolvers/DecimalResolverTest.php +++ b/tests/Unit/Resolvers/DecimalResolverTest.php @@ -54,6 +54,15 @@ public function test_fake_method_can_working_well_with_bracket(): void $this->assertEquals('\''.$resolver->field.'\' => fake()->randomFloat(2, 0, 999999),', $resolver->fake()); } + public function test_cast_can_working_well_with_bracket(): void + { + $this->column->bracket = '8, 2'; + + $resolver = new DecimalResolver($this->column); + + $this->assertEquals('decimal:2', $resolver->cast()); + } + public function test_migration_method_can_working_well(): void { $resolver = new DecimalResolver($this->column);