Skip to content

Commit

Permalink
Update CurrencyRule.php
Browse files Browse the repository at this point in the history
  • Loading branch information
iRaziul committed Feb 6, 2024
1 parent 3e3a432 commit db84244
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Rules/CurrencyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
namespace Akaunting\Money\Rules;

use Akaunting\Money\Currency;
use Illuminate\Contracts\Validation\Rule;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class CurrencyRule implements Rule
class CurrencyRule implements ValidationRule
{
public function passes($attribute, $value): bool
public function validate(string $attribute, mixed $value, Closure $fail): void
{
return is_string($value) && key_exists(strtoupper($value), Currency::getCurrencies());
if (! $this->passes($value)) {
$fail('money.invalid-currency')->translate();
}
}

public function message()
protected function passes($value): bool
{
/** @var string */
return trans('money.invalid-currency');
return is_string($value) && array_key_exists(strtoupper($value), Currency::getCurrencies());
}
}

0 comments on commit db84244

Please sign in to comment.