Help Needed: Updating a Column When Validating User Input with Custom Rules in Filament #15208
Unanswered
obahchimaobi
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Package
Form builder
Package Version
v3.0
How can we help you?
I'm working on a FilamentPHP form where users are required to input a code during registration. This code needs to be validated against the database for two conditions:
Existence: The code must exist in the Codes table.
Usage: The code must not have already been used (checked using the is_used column).
Additionally, when the input code passes validation, I want to update the is_used column for that code to true. Below is my current implementation:
`
return TextInput::make('code')
->required()
->rules([
fn(): Closure => function (string $attribute, $value, Closure $fail) {
if (!Codes::where('code', $value)->exists()) {
$fail('The :attribute is invalid.');
}
},
`
The code works well for validation, but I’m not sure how to update the is_used column to true for the input code after the validation succeeds. I'm looking for guidance on where and how to add this logic.
Codes::where('code', $value)->update(['is_used' => true]);
Beta Was this translation helpful? Give feedback.
All reactions