Skip to content
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
34 changes: 2 additions & 32 deletions src/Rules/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ class Money implements Rule
{
use WithParameters;

/**
* The callback that should be used to validate the locale.
*/
public static $localeCallback;

/**
* The callback that should be used to validate the currency.
*/
public static $currencyCallback;

/**
* Determine if the validation rule passes.
*/
Expand All @@ -38,22 +28,6 @@ public function message(): string
return Helpers::getMessage('money');
}

/**
* Set callback to get locale to be used in the validation rule.
*/
public static function setLocaleCallback(callable $callback): void
{
static::$localeCallback = $callback;
}

/**
* Set callback to get currency to be used in the validation rule.
*/
public static function setCurrencyCallback(callable $callback): void
{
static::$currencyCallback = $callback;
}

/**
* Determine if the money is valid.
*/
Expand All @@ -71,18 +45,14 @@ private function checkMoney(mixed $value): bool
*/
private function getLocale(): mixed
{
$default = data_get($this->parameters, '1');

return with($default, static::$localeCallback);
return data_get($this->parameters, '1');
}

/**
* Get the currency from callback or parameters.
*/
private function getCurrency(): mixed
{
$default = data_get($this->parameters, '0', 'USD');

return with($default, static::$currencyCallback);
return data_get($this->parameters, '0', 'USD');
}
}
4 changes: 3 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ private function bootRules(): void
return $rule->passes($attribute, $value);
};

$this->app['validator']->extend($name, $extension, $rule->message());
$this->app['validator']->extend($name, $extension);

$this->app['validator']->replacer($name, fn () => $rule->message());
});
}

Expand Down