Laravel Settings with multi checkox list #294
Unanswered
mikemastercorp
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello all.
I am learning Filament Admin Panel and since it has a nice plugin that adapts the Spatie Settings, I decided it will be nice to prepare a starter kit that can be shared with anyone free of charge to have a look, try and if OK to use for their projects and save some DEV time.
So as part of my settings page, I decided to use a single page and having content settings divided by tabs (just to emulate a standard configuration page).
It all worked perfectly well and my idea is to add all possible form input fields as setting example, so that anyone who needs one, can simply repurpose the example code and get rid of the rest.
I've reached to the CheckBos list which provides multiple checkboxes and allows an array of values to be selected. I am able to show the form, however when I try to store the data, I get the error:
Cannot` assign array to property App\Settings\GeneralSettings::$site_checkboxlist of type string
Tried to define the public variable $site_checkboxlist as an array, but then I got another error:
Cannot assign string to property App\Settings\GeneralSettings::$site_checkboxlist of type array
I've read some extra materials about casting and that I should do that on the model etc. but i am not sure in this case what needs to be done so that multiple values can either be stored as an array or as a string in a CSV format (e.g. string1,string2,string3) which I can then explode to an array or create a collection.
My current checkbox list form markup is:
// 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 ==' ]) // set the number of columns to order the list options (equal number of coluns and choices makes them horizonta) ->columns(3), // ->label('') // set an empty label value to hide it
Beta Was this translation helpful? Give feedback.
All reactions