Custom validation rules
I am currently using a custom validation rule on a form. I would like to use the same rule in filament, but I do not know how.
This is the rule:
$request->validate([
"onlineRegistration" => [new OneOf($request, ["onlineRegistration","registrationLink","registrationEmail"])],
"registrationLink" => [new OneOf($request, ["onlineRegistration","registrationLink","registrationEmail"])],
"registrationEmail" => [new OneOf($request, ["onlineRegistration","registrationLink","registrationEmail"])],
]);
In filament, I tried this:
Toggle::make('onlineRegistration')->rules([new OneOf(request(), ["onlineRegistration","registrationLink","registrationEmail"])]),
But it always shows a validation error6 Replies
What is OneOf? Afaik that's not standard Laravel. I assume it's some custom class that checks to see if one of the provided array values exists in the given object. But Filament doesn't use request(), it's Livewire.
Describe what your form and validation is actually trying to achieve.
I am using this custom rule: https://stackoverflow.com/questions/66280012/laravel-validation-rule-for-either-of-two-fields-required-but-both-should-not-be
Stack Overflow
Laravel validation rule for either of two fields required but both ...
Is there a Laravel validation rule for when either of two fields are required but both should not be present at the same time.
Eg. Mobile number and email, either of them should be present but not ...
I have three fields and only one of those should be present
Yeah, that's not going to work for Filament, as it doesn't use the $request object. Livewire is not controller / request based.
You'll need to roll your own custom validation using $get ...
https://filamentphp.com/docs/3.x/forms/validation#custom-rules
Maybe something like ...
Thanks, this works, just had change it a bit so it works with v2: