Spatie Settings with Filament CheckboxList

Hello gents. I am posting here a topic which I've also posted in Filament but so far could not get any luck figuring out the things. My idea was to build a Filament-Starter-Kit which can be freely used to download, install and have a full admin panel with Filament + Jetstreal (using last one to allow 2FA) + Settings page with an example for every input and many other plugins I manage to install like Spatie Roles& Permissions, Backup etc. So I got all setup with latest filament + jetstream + Spatie settings and have built a Settings page with a few examples. The issue started when I tried to add a Form CheckboxList input to Settings as I am defining the $settings_checkboxlist as string and Filament complained that I cannot store an array to a string type variable. If I try to set it up as an array type variable, Filament complains again that I am trying to store data to an array type variable, so I am stuck and can't move forward trying to figure out what is going on. From what I am reading, to store the data, I somehow need to cast the $site_checkboxlist inside the GeneralSettings.php which extends the settings, but so far I could not figure it out how to cast it properly so that the data is stored and I can continue adding other fields. long story short, how to store array data to Settings page... Here is the link to the filament topic where I've shared also the link to the repo itself with the latest code... https://discord.com/channels/883083792112300104/1290405438575087647 Any help is more than appreciated as I am trying to build complex admin in order to learn it, have some coding fun and share it with the community afterwords...
Solution:
Nevermind, Tuto, I've figured it out, it was just that in the DB I did not define the initial column payload as [] but '' and not sure why but since I switched to that and set my variable as an array type, I got it working perfectly. So my current settinfs page has the following definitions (in case you ever fall into this, despite I doubt it): GeneralSettingsPage.php...
Jump to solution
5 Replies
MilenKo
MilenKoOPβ€’3mo ago
Hey @tuto1902 Maybe you've had such a need in all the project and have resolved it somehow? I've posted the link to my repo for the full source if that helps... All I need is to store a CheckboxList data of checked boxes to the Settings $site_checkboxlist variable and DB. Defining it as an array type returns an error that I am trying to store sting to an array type variable, defining it as a string returns reverse, so I am buffled for almost a week now and can't figure out what on Earth is happening... No AI so far could help as well 😦
tuto1902
tuto1902β€’3mo ago
I’ll look into it and let you know.
MilenKo
MilenKoOPβ€’3mo ago
Thank you in advance. Trying to do and share some good with the Open Source community but this wone seems to be a tough nut to crack. Btw, the Filament + Jetstream - I did it already and the code is in the repo, so now we have 2FA in the user profiles while using Filament πŸ™‚ And there seem to be many useful plugins for a starter pack, but I just can't get on hold of the array<>string type var storing... It definitely has to do something with the casts, but I am not really sure which cast to use and how to pass the proper parameters as most (if not all) casts available in LaravelSettings plugin I've tried but could not make it work as it should..
MilenKo
MilenKoOPβ€’3mo ago
This is what I am trying to store, all others work like a charm, but they hold a single value. I believe a similar issue will arise with the repeater input so knowing how to store an arrray to string or to use an array to store in a single column will be of help there too
No description
Solution
MilenKo
MilenKoβ€’3mo ago
Nevermind, Tuto, I've figured it out, it was just that in the DB I did not define the initial column payload as [] but '' and not sure why but since I switched to that and set my variable as an array type, I got it working perfectly. So my current settinfs page has the following definitions (in case you ever fall into this, despite I doubt it): GeneralSettingsPage.php
// All CheckboxList options: https://filamentphp.com/docs/3.x/forms/fields/checkbox-list
CheckboxList::make('site_checkboxlist') // checkbox list with supplied options
->options([
'1' => '== A ==',
'2' => '== B ==',
'3' => '== C =='
]),
// All CheckboxList options: https://filamentphp.com/docs/3.x/forms/fields/checkbox-list
CheckboxList::make('site_checkboxlist') // checkbox list with supplied options
->options([
'1' => '== A ==',
'2' => '== B ==',
'3' => '== C =='
]),
GeneralSettings.php
// Define the settings page inputs to use in the Settings Page
public array $site_checkboxlist; // Note: Changed this back to an array
...
// Define the settings page inputs to use in the Settings Page
public array $site_checkboxlist; // Note: Changed this back to an array
...
And my settings table migration:
...
$this->migrator->add('general.site_checkboxlist', []); // checkbox list input
...
...
$this->migrator->add('general.site_checkboxlist', []); // checkbox list input
...
Just sharing the solution here, but the working code can be seen in the repo and I am moving forward with other inputs to see what hides there as well πŸ˜‰ At least I can handle arrays now in Filament to properly store the values... πŸ˜‰
Want results from more Discord servers?
Add your server