namespace Cubist\Backpack\Middleware;
use Closure;
+use Cubist\Util\Json;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
$appendComposite = [];
$newBag = [];
+ $init = $request->all();
foreach ($request->all() as $field => $content) {
$e = explode('___', $field);
if (count($e) > 1) {
}
Arr::set($appendComposite, $field, $content);
} else {
+ if (is_string($content) && stristr($content, '___') && Json::isJson($content)) {
+ $data = json_decode($content, true);
+ $this->normalizeBunchInBunch($data);
+ $content = $data;
+ }
$newBag[$field] = $content;
}
}
return $this->getResponse();
}
+
+ protected function normalizeBunchInBunch(&$data)
+ {
+ foreach ($data as $k => $v) {
+ if (is_array($v)) {
+ $this->normalizeBunchInBunch($v);
+ }
+ if (stristr($k, '___')) {
+ $e = explode('___', $k);
+ $varname = $e[0];
+ $sub = $e[1];
+ if (!isset($data[$varname])) {
+ $data[$varname] = [];
+ }
+ $data[$varname][$sub] = $v;
+ unset($data[$k]);
+ } else {
+ $data[$k] = $v;
+ }
+ }
+ }
}