Skip to content

Commit

Permalink
Fix a decimal error in models (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
cable8mm authored Jan 7, 2025
1 parent 0ce1cea commit 3682ce4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Resolvers/DecimalResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
9 changes: 9 additions & 0 deletions tests/Unit/Resolvers/DecimalResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3682ce4

Please sign in to comment.