F
Filamentβ€’15mo ago
alex123x5

Check if value is true, and check the checkbox on update

I have a multi tenancy setup. But when i want to edit an tenancy I want to have all checkboxes checked if they are true in the json object from the database. How can I do this?
CheckboxList::make('settings')
->options([
'twitter' => 'Twitter',
'linkedin' => 'LinkedIn',
'whatsapp' => 'WhatsApp',
'email' => 'Email',
'copy' => 'Copy',
])
->descriptions([
'twitter' => 'Enable sharing on Twitter (x)',
'linkedin' => 'Enable sharing on LinkedIn',
'whatsapp' => 'Enable sharing on WhatsApp',
'email' => 'Enable sharing on Email',
'copy' => 'Enable sharing through coping the link',
])
CheckboxList::make('settings')
->options([
'twitter' => 'Twitter',
'linkedin' => 'LinkedIn',
'whatsapp' => 'WhatsApp',
'email' => 'Email',
'copy' => 'Copy',
])
->descriptions([
'twitter' => 'Enable sharing on Twitter (x)',
'linkedin' => 'Enable sharing on LinkedIn',
'whatsapp' => 'Enable sharing on WhatsApp',
'email' => 'Enable sharing on Email',
'copy' => 'Enable sharing through coping the link',
])
{
"copy": false,
"email": false,
"twitter": true,
"linkedin": false,
"whatsapp": false
}
{
"copy": false,
"email": false,
"twitter": true,
"linkedin": false,
"whatsapp": false
}
So if in this example twitter is true, then I want to have the checkbox for twitter checked. Is this possible?
4 Replies
awcodes
awcodesβ€’15mo ago
Is settings a relationship to the model or a db column on the model.?
alex123x5
alex123x5OPβ€’15mo ago
It is a db column I've already tried it with using ->default([false, false, true, false, false]) but that doesn't work
awcodes
awcodesβ€’15mo ago
i would create a record through the filament form to see exactly how the data is stored in the db, then use that to reconstruct it where you need to. Also keep in mind that ->default() only works in the 'create' context. So you can't use it to prefil the field in the 'edit' context.
alex123x5
alex123x5OPβ€’15mo ago
I've created this one (from the example) through the form. Or I don't understand it that is also possible πŸ˜‰ Didn't know what happened but now, with a fresh database it works. So yeah either way, thanks for the suggestions!
Want results from more Discord servers?
Add your server