Good morning ! I am preparing my database for use HighMaps with Laravel5, I receive this JSON form since Laravel.
[{"hc-key":"es-vi"},{"hc-key":"es-cs"},{"hc-key":"es-lo"},{"hc-key":"es-z"}]
Higchamps needs the following format:
var data = [{ 'hc-key': 'es-pm', value: 0 },
{ 'hc-key': 'es-va', value: 1 },
{ 'hc-key': '', value: 52 }];
How could I send the format data that Highmaps need?
The sql in controller is this:
$provincias= DB::table('provincia')->lists('hc-key');
Since I'm not really sure where you would get the "values" you speak of, and, I'm assuming you know where those values come from, the easiest way I can come up with quickly is to use json_decode and json_encode.
$data = '[{"hc-key":"es-vi"},{"hc-key":"es-cs"},{"hc-key":"es-lo"},{"hc-key":"es-z"}]';
$data = json_decode($data);
foreach ($data as $item) {
if ($item->{'hc-key'} == 'your_key_here') {
$item->value = 'your_numeric_value_here';
}
}
$data = json_encode($data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With