Booleans are stored as strings
jbardnz opened this issue · comments
Is it possible to have them stored/retrieved as booleans or do they have to be saved as strings?
Hi jbardnz
you can it by using array value
Setting::set('usa',array(
'florida' => '689',
'texas'=>'210',
'california'=>'213'
)) ;
Setting::save();
and when call return Setting::get('usa');
{
florida: "689",
texas: "210",
california: "213"
}
Just that's it.
I think, this does not answer the original question!
He tries to save a Setting as boolean, just like this:
Setting::set('receiveEMails', true);
Setting::save();
But if you try to get the value back, it is converted as string:
echo (Setting::get('receiveEMails'));
The setter
above results in the following settings
attribute in your database:
{"receiveEMails":true}
Reading the setting (as described above) will return the value as a boolean (e.g., in this case, true
). You can simply verify this by using var_dump(Setting::get('receiveEMails'));
, which should output (bool)true
.
Hope, this helps!
Cheers
Hey @johannesschobel yes that is exactly what I was trying to describe!
Thanks
Hey @jbardnz , glad it worked out for you. Do you have any other questions regarding this topic? Otherwise you may close the issue ;)
Thanks for picking this up @johannesschobel.