Toggle implementation Using Sqlite

I am using sqlite which doesnt have a Boolean datatype. Can I still use the toggle feature? I tried just creating a text column and adding code on filament treating toggle as a boolean, but it isnt saving to the DB.
6 Replies
toeknee
toeknee2y ago
Try removing the boolean approach in the cast since the DB doesn't support it, it depends how strict the datatype is when we render it as natively in php 1, 0 are true and false too. If it updates but doesn't render the change use:
->formatStateUsing(fn($state) => $state == '1' ? true : false)
->formatStateUsing(fn($state) => $state == '1' ? true : false)
Dennis Koch
Dennis Koch2y ago
The cast is all you should need. Is is_admin fillable?
toeknee
toeknee2y ago
Does cast not case to the DB too and if it's boolean it would fail filling?
Dennis Koch
Dennis Koch2y ago
It's also stored as 0/1 in MySQL
toodles
toodlesOP2y ago
Thats what was missing...adding it there got it to work. Thanks @Dennis Koch & @toeknee_iom
toeknee
toeknee2y ago
If you are using filament for all your model inputs, then just disable model fillables as per the filament docs.
Want results from more Discord servers?
Add your server