Skip to content

Commit

Permalink
fix: resolve attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangkhacphuc committed Mar 21, 2024
1 parent 8eb0a11 commit 1a5f976
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Rules/Traits/ResolveAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Sphoton\Validation\Rules\Traits;

trait ResolveAttribute
{
public function resolveAttribute($attribute)
{
return str_replace('_', ' ', $attribute);
}
}
3 changes: 2 additions & 1 deletion src/Rules/VietnameseNumberRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class VietnameseNumberRule implements ValidationRule
{
use Traits\IsVietnamese;
use Traits\ResolveAttribute;

/**
* Run the validation rule.
Expand All @@ -18,7 +19,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (! is_string($value) || ! $this->isVietnamese($value, '0-9')) {
$fail('sphoton::validation.vietnamese')->translate([
'attribute' => $attribute,
'attribute' => $this->resolveAttribute($attribute),
]);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Rules/VietnameseRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class VietnameseRule implements ValidationRule
{
use Traits\IsVietnamese;
use Traits\ResolveAttribute;

/**
* Run the validation rule.
Expand All @@ -18,7 +19,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (! is_string($value) || ! $this->isVietnamese($value)) {
$fail('sphoton::validation.vietnamese')->translate([
'attribute' => $attribute,
'attribute' => $this->resolveAttribute($attribute),
]);
}
}
Expand Down

0 comments on commit 1a5f976

Please sign in to comment.