F
Filament13mo ago
KA

beforeStateUpdated is not working on Tables\Columns\ToggleColumn

Trying to update the $state before update. Used following code: Tables\Columns\ToggleColumn::make('email_verified_at') ->beforeStateUpdated(function ($record, $state) { return $state?date('Y-m-d H:i:s'):NULL; }) Am i missed anything?
No description
9 Replies
tesse05
tesse0513mo ago
I think you can't use a toggle for datetime fields.... email_verified_at is a datetime field
KA
KAOP13mo ago
issue is the $stack is not updating when updating the record
einnlleinhatt_
einnlleinhatt_13mo ago
Not sure if you can
toeknee
toeknee13mo ago
You need to set it as null, that is trying to set it as 0 and the field cannot take 0 for datetime. only null if nullable.
KA
KAOP13mo ago
to be clear, the toggle only returns true (1) or false (0) and it updates the record. In this case I need to set null instead of false, so I used beforeStateUpdated() the method to set it before update. Did I made any mistake on that? kindly advice. fyki, the toggle looks fine but unable to update
einnlleinhatt_
einnlleinhatt_13mo ago
You need to change the return to date time or null, that's if you can. But I'm not sure you can since toggle return boolean
KA
KAOP13mo ago
sorry if i talk like stupid 😦 it actually works on datetime field
No description
einnlleinhatt_
einnlleinhatt_13mo ago
Ohh nice you made it. I tried it yesterday it keep giving me warning about 1 and 0 things.
KA
KAOP13mo ago
i think you need to update your filament
Want results from more Discord servers?
Add your server