src/Services/NestableService.php
public function renderAsDropdown($data = false, $parent = 0, $first = true, $level = 0)
    {
        $args = $this->setParameters(func_get_args());

        $tree = '';

        // open the select tag
        if ($first) {
            $tree = $first ? '<select '.$this->addAttributes().' ' : '';
        }
        // if pass array data to selected method procces will generate multiple dropdown menu.
        if ($first && $this->multiple == true) {
            $tree .= ' multiple';
        }

        if ($first) {
            $tree .= '>';

            if(current($this->placeholder)) {
                $tree .= '<option value="'.key($this->placeholder).'">' . current($this->placeholder) . '</option>';
            }
        }

        $args['data']->each(function ($child_item) use (&$tree, $args, $level) {

            $childItems = '';

            if (intval($child_item[$this->parent]) == intval($args['parent'])) {

                // Get the value
                $value = $child_item[$this->config['dropdown']['value']];

                // Get the label text
                $label = $child_item[$this->config['dropdown']['label']];

                $prefix = $this->config['dropdown']['prefix'];

                // Generating nest level
                $levels = str_repeat('&nbsp;&nbsp;', $level);

                // check the does want select value
                $selected = $this->doSelect($value, $label);

                // Generating dropdown item
                $childItems .= '<option '.$selected.' value="'.$value.'">'.$levels.$prefix.$label.'</option>';

                $item_id = $child_item[$this->config['primary_key']];

                // check the child element
                if ($this->hasChild($this->parent, $item_id, $args['data'])) {
                    ++$level; // nest level increasing

                    // function call again for child elements
                    $childItems .= $this->renderAsDropdown($args['data'], $item_id, false, $level);
                }
            }

            // current data contact to the parent variable
            $tree = $tree.$childItems;

        });

        // close the select tag
        $tree = $first ? $tree.'</select>' : $tree;

        return $tree;
    }
public function renderAsDropdown($data = false, $parent = 0, $first = true, $level = 0)
    {
        $args = $this->setParameters(func_get_args());

        $tree = '';

        // open the select tag
        if ($first) {
            $tree = $first ? '<select '.$this->addAttributes().' ' : '';
        }
        // if pass array data to selected method procces will generate multiple dropdown menu.
        if ($first && $this->multiple == true) {
            $tree .= ' multiple';
        }

        if ($first) {
            $tree .= '>';

            if(current($this->placeholder)) {
                $tree .= '<option value="'.key($this->placeholder).'">' . current($this->placeholder) . '</option>';
            }
        }

        $args['data']->each(function ($child_item) use (&$tree, $args, $level) {

            $childItems = '';

            if (intval($child_item[$this->parent]) == intval($args['parent'])) {

                // Get the value
                $value = $child_item[$this->config['dropdown']['value']];

                // Get the label text
                $label = $child_item[$this->config['dropdown']['label']];

                $prefix = $this->config['dropdown']['prefix'];

                // Generating nest level
                $levels = str_repeat('&nbsp;&nbsp;', $level);

                // check the does want select value
                $selected = $this->doSelect($value, $label);

                // Generating dropdown item
                $childItems .= '<option '.$selected.' value="'.$value.'">'.$levels.$prefix.$label.'</option>';

                $item_id = $child_item[$this->config['primary_key']];

                // check the child element
                if ($this->hasChild($this->parent, $item_id, $args['data'])) {
                    ++$level; // nest level increasing

                    // function call again for child elements
                    $childItems .= $this->renderAsDropdown($args['data'], $item_id, false, $level);
                }
            }

            // current data contact to the parent variable
            $tree = $tree.$childItems;

        });

        // close the select tag
        $tree = $first ? $tree.'</select>' : $tree;

        return $tree;
    }
public function renderAsDropdown ( $ data = false , $ parent = 0 , $ first = true , $ level = 0 ) { $ args = $ this -> setParameters ( func_get_args ( ) ) ; $ tree = '' ; // open the select tag if ( $ first ) { $ tree = $ first ? '<select ' . $ this -> addAttributes ( ) . ' ' : '' ; } // if pass array data to selected method procces will generate multiple dropdown menu. if ( $ first && $ this -> multiple == true ) { $ tree .= ' multiple' ; } if ( $ first ) { $ tree .= '>' ; if ( current ( $ this -> placeholder ) ) { $ tree .= '<option value="' . key ( $ this -> placeholder ) . '">' . current ( $ this -> placeholder ) . '</option>' ; } } $ args [ 'data' ] -> each ( function ( $ child_item ) use ( & $ tree , $ args , $ level ) { $ childItems = '' ; if ( intval ( $ child_item [ $ this -> parent ] ) == intval ( $ args [ 'parent' ] ) ) { // Get the value $ value = $ child_item [ $ this -> config [ 'dropdown' ] [ 'value' ] ] ; // Get the label text $ label = $ child_item [ $ this -> config [ 'dropdown' ] [ 'label' ] ] ; $ prefix = $ this -> config [ 'dropdown' ] [ 'prefix' ] ; // Generating nest level $ levels = str_repeat ( '&nbsp;&nbsp;' , $ level ) ; // check the does want select value $ selected = $ this -> doSelect ( $ value , $ label ) ; // Generating dropdown item $ childItems .= '<option ' . $ selected . ' value="' . $ value . '">' . $ levels . $ prefix . $ label . '</option>' ; $ item_id = $ child_item [ $ this -> config [ 'primary_key' ] ] ; // check the child element if ( $ this -> hasChild ( $ this -> parent , $ item_id , $ args [ 'data' ] ) ) { ++ $ level ; // nest level increasing // function call again for child elements $ childItems .= $ this -> renderAsDropdown ( $ args [ 'data' ] , $ item_id , false , $ level ) ; } } // current data contact to the parent variable $ tree = $ tree . $ childItems ; } ) ; // close the select tag $ tree = $ first ? $ tree . '</select>' : $ tree ; return $ tree ; }
Convert to dropdown.

@param object $data   Illuminate\Support\Collection
@param int    $parent Current parent id
@param bool   $first  first run
@param int    $level  nest counter

@return string
Convert to dropdown .