Fix setting drop downs not being saved properly #148

This commit is contained in:
Nabeel Shahzad 2018-01-21 13:36:03 -05:00
parent c732268bd7
commit e86fd64235
2 changed files with 26 additions and 3 deletions

View File

@ -1,5 +1,26 @@
<?php
if(!function_exists('list_to_assoc')) {
/**
* Converts a straight list into an assoc array with
* key and value being the same. Mainly for a select box
*
* e.g.:
* [ 0 => 'item1', 1 => 'item2']
* to:
* ['item1' => 'item1', 'item2' => 'item2']
*
* @param array $list
* @return \Illuminate\Support\Collection
*/
function list_to_assoc(array $list)
{
return collect($list)->mapWithKeys(function ($item) {
return [$item => $item];
});
}
}
if (!function_exists('skin_view')) {
/**
* Render a skin

View File

@ -23,9 +23,11 @@
@elseif($setting->type === 'int' || $setting->type === 'number')
{!! Form::number($setting->id, $setting->value, ['class'=>'form-control']) !!}
@elseif($setting->type === 'select')
{!! Form::select($setting->id,
explode(',', $setting->options),
$setting->value, ['class' => 'select2', 'style' => 'width: 100%; text-align: left;']) !!}
{!! Form::select(
$setting->id,
list_to_assoc(explode(',', $setting->options)),
$setting->value,
['class' => 'select2', 'style' => 'width: 100%; text-align: left;']) !!}
@else
{!! Form::input('text', $setting->id, $setting->value, ['class' => 'form-control']) !!}
@endif