Text Input Column Validation Not Working

Hi, I am trying to add a rule (validation check ) to the date text input column rendered in table builder but for some reason it is not working also is there any way i can access the record in the function because unable to do that as well; it gives the input state Code: TextInputColumn::make('deadline') ->type('date') ->rules([ fn ($record, $component) => function ($attributes, $value, $fail) use ($record) { if ($value < now()->format('Y-m-d')) { $fail('Closing date must be greater than or equal to ' . now()->format('Y-m-d')); } elseif ($value < $record->deadline?->format('Y-m-d')) { $fail("Closing date must be greater than or equal to last saved date ({$record->deadline->format('Y-m-d')})"); } }, 'nullable'], ) ->getStateUsing(fn ($record) => $record->deadline?->format('Y-m-d')),
2 Replies
awcodes
awcodes2mo ago
Can you dd $value in the validator. It might not be a Carbon instance. So comparing it won’t work without converting it to a carbon instance.
lolmaheen
lolmaheen2mo ago
Passing the record parameter makes this unexecutable fn ($record, $component) => function ($attributes, $value, $fail) use ($record) if i used it directly:
->rules([ function ($attributes, $value, $fail)
It gets executed but I want to access the $record to compare updated value with the original record value.
Want results from more Discord servers?
Add your server