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:Jump to 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...
5 Replies
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 π¦
Iβll look into it and let you know.
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..
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
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
GeneralSettings.php
And my settings table migration:
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... π