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 validation extensions #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

frknakk
Copy link

@frknakk frknakk commented Sep 4, 2024

$request->validate([
	'vat_id' => [new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberFormat()],
]);

Using rules as object works


$request->validate([
	'vat_id' => 'vat_number_format',
]);

But using rules as string shortcut does not work


Problem

// VatValidatorServiceProvider.php
Validator::extend('vat_number_format', static function ($attribute, $value, $parameters, $validator): void {
	$rule = new VatNumberFormat();
	$rule->validate($attribute, $value, static fn (string $message = null): null => null);
});

The function does the validation, but just completely ignores the result. It has to return the validation result as boolean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant