/** * {@inheritdoc} * * @param array $input * @param array $metadata (optional) * @return array **/ public function castInput(array $input, array $metadata = []) { $filtered = []; foreach ($input as $key => $value) { // tokens, _method... if (starts_with($key, '_')) { continue; } // actions if (str_contains($key, '-')) { continue; } if ($this->removeConfirmations && ends_with($key, '_confirmation')) { continue; } $filtered[$key] = $value; } return NestedArray::toNested($filtered, '__'); }
protected function registerInputCasters($caster) { $caster->add('no_leading_underscore', function ($input) { $cleaned = []; foreach ($input as $key => $value) { // tokens, _method... if (!starts_with($key, '_')) { $cleaned[$key] = $value; } } return $cleaned; }); $caster->add('no_actions', function ($input) { $cleaned = []; foreach ($input as $key => $value) { // form actions if (!str_contains($key, '-')) { $cleaned[$key] = $value; } } return $cleaned; }); $caster->add('no_confirmations', function ($input) { $cleaned = []; foreach ($input as $key => $value) { // form actions if (!ends_with($key, '_confirmation')) { $cleaned[$key] = $value; } } return $cleaned; }); $caster->add('nested', function ($input) { return NestedArray::toNested($input, '.'); }); $caster->add('dotted', function ($input) { $cleaned = []; foreach ($input as $key => $value) { // form naming to dots $cleaned[str_replace('__', '.', $key)] = $value; } return $cleaned; }); }