protected function flatNamedElements(Collection $elements)
    {
        return $elements->reduce(function (Collection $initial, $element) {
            if ($element instanceof NamedFormElement) {
                // Is it what we're looking for? if so we'll push it to final collection
                $initial->push($element);
            } elseif ($element instanceof FormElements) {
                // Go deeper and repeat everything again
                return $initial->merge($this->flatNamedElements($element->getElements()));
            }

            return $initial;
        }, collect());
    }
protected function flatNamedElements(Collection $elements)
    {
        return $elements->reduce(function (Collection $initial, $element) {
            if ($element instanceof NamedFormElement) {
                // Is it what we're looking for? if so we'll push it to final collection
                $initial->push($element);
            } elseif ($element instanceof FormElements) {
                // Go deeper and repeat everything again
                return $initial->merge($this->flatNamedElements($element->getElements()));
            }

            return $initial;
        }, collect());
    }
protected function flatNamedElements ( Collection $ elements ) { return $ elements -> reduce ( function ( Collection $ initial , $ element ) { if ( $ element instanceof NamedFormElement ) { // Is it what we're looking for? if so we'll push it to final collection $ initial -> push ( $ element ) ; } elseif ( $ element instanceof FormElements ) { // Go deeper and repeat everything again return $ initial -> merge ( $ this -> flatNamedElements ( $ element -> getElements ( ) ) ) ; } return $ initial ; } , collect ( ) ) ; }
Returns flat collection of elements in form ignoring everything but NamedFormElement. Works recursive.

@param \Illuminate\Support\Collection $elements

@return mixed
Returns flat collection of elements in form ignoring everything but NamedFormElement . Works recursive .