Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a decimal error in models #102

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading