F
Filament14mo ago
toodles

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
toeknee14mo 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 Koch14mo ago
The cast is all you should need. Is is_admin fillable?
toeknee
toeknee14mo ago
Does cast not case to the DB too and if it's boolean it would fail filling?
Dennis Koch
Dennis Koch14mo ago
It's also stored as 0/1 in MySQL
toodles
toodles14mo ago
Thats what was missing...adding it there got it to work. Thanks @Dennis Koch & @toeknee_iom
toeknee
toeknee14mo ago
If you are using filament for all your model inputs, then just disable model fillables as per the filament docs.