i'm using distinct , lists retrieve list of values have been inserted.
$listcolor = $group->where('map_polygon_color', '!=', '')->distinct('map_polygon_color')->lists('map_polygon_color');
generates me solid list of colors.
now fetch (if there selected color) color:
$selectedcolor = array_search($group->map_polygon_color, $listcolor);
ok, got list colors , selected list. send model-binded form:
{!! form::select('map_polygon_color', $listcolor, $selectedcolor, ['class' => 'form-control']) !!}
now question: there (simpel) way directly in template? selectedcolor needs color list array retrieve selected key.
// edit color array:
array:5 [▼ 0 => "rgb(75, 0, 130)" 1 => "rgb(50, 205, 50)" 2 => "rgb(30, 144, 255)" 3 => "rgb(255, 140, 0)" 4 => "rgb(255, 0, 0)" ]
i'm not sure if works make $listcolor
array this:
[ 'rgb(75, 0, 130)' => 'rgb(75, 0, 130)', 'rgb(50, 205, 50)' => 'rgb(50, 205, 50)' // etc ]
by using map_polygon_color
twice in lists
:
$listcolor = $group->where('map_polygon_color', '!=', '') ->distinct('map_polygon_color') ->lists('map_polygon_color', 'map_polygon_color');
then you'd @ least not have array_search
, if understand structure correctly model binding should take care of setting right value:
{!! form::select('map_polygon_color', $listcolor, null, ['class' => 'form-control']) !!}