src/Generators/HtmlGenerator.php
public function makeRelationship($config, $label = 'name', $value = 'id', $custom = '')
    {
        $object = $config['object'];

        if (isset($config['config']['relationship'])) {
            $relationship = $config['config']['relationship'];
        } else {
            $relationship = $config['name'];
        }

        // Removes the array indication for select multiple
        $relationship = str_replace('[]', '', $relationship);

        $method = 'all';

        if (!is_object($config['config']['model'])) {
            $class = app()->make($config['config']['model']);
        } else {
            $class = $config['config']['model'];
        }

        if (isset($config['config']['method'])) {
            $method = $config['config']['method'];
        }

        if (isset($config['config']['params'])) {
            $items = $class->$method($config['config']['params']);
        } else {
            $items = $class->$method();
        }

        if (isset($config['config']['nullable']) && $config['config']['nullable'] === true) {
            $config['config']['options']['- Select -'] = null;
        }
        foreach ($items as $item) {
            $config['config']['options'][$item->$label] = $item->$value;
        }

        if (!isset($config['config']['selected'])) {
            if (!isset($config['config']['multiple'])) {
                $selected = '';

                if (is_object($object) && method_exists($object, $relationship)) {
                    if ($object->$relationship()->first()) {
                        $selected = $object->$relationship()->first()->$value;
                    }
                }

                $relationship = str_replace('_id', '', $relationship);

                if (method_exists($object, $relationship)) {
                    if ($object->$relationship()->first()) {
                        $selected = $object->$relationship()->first()->$value;
                    }
                }
            } else {
                $selected = $class->$method()->pluck($value, $label);
            }
        } else {
            $selected = $config['config']['selected'];
        }

        return $this->makeSelected($config, $selected, $custom);
    }
public function makeRelationship($config, $label = 'name', $value = 'id', $custom = '')
    {
        $object = $config['object'];

        if (isset($config['config']['relationship'])) {
            $relationship = $config['config']['relationship'];
        } else {
            $relationship = $config['name'];
        }

        // Removes the array indication for select multiple
        $relationship = str_replace('[]', '', $relationship);

        $method = 'all';

        if (!is_object($config['config']['model'])) {
            $class = app()->make($config['config']['model']);
        } else {
            $class = $config['config']['model'];
        }

        if (isset($config['config']['method'])) {
            $method = $config['config']['method'];
        }

        if (isset($config['config']['params'])) {
            $items = $class->$method($config['config']['params']);
        } else {
            $items = $class->$method();
        }

        if (isset($config['config']['nullable']) && $config['config']['nullable'] === true) {
            $config['config']['options']['- Select -'] = null;
        }
        foreach ($items as $item) {
            $config['config']['options'][$item->$label] = $item->$value;
        }

        if (!isset($config['config']['selected'])) {
            if (!isset($config['config']['multiple'])) {
                $selected = '';

                if (is_object($object) && method_exists($object, $relationship)) {
                    if ($object->$relationship()->first()) {
                        $selected = $object->$relationship()->first()->$value;
                    }
                }

                $relationship = str_replace('_id', '', $relationship);

                if (method_exists($object, $relationship)) {
                    if ($object->$relationship()->first()) {
                        $selected = $object->$relationship()->first()->$value;
                    }
                }
            } else {
                $selected = $class->$method()->pluck($value, $label);
            }
        } else {
            $selected = $config['config']['selected'];
        }

        return $this->makeSelected($config, $selected, $custom);
    }
public function makeRelationship ( $ config , $ label = 'name' , $ value = 'id' , $ custom = '' ) { $ object = $ config [ 'object' ] ; if ( isset ( $ config [ 'config' ] [ 'relationship' ] ) ) { $ relationship = $ config [ 'config' ] [ 'relationship' ] ; } else { $ relationship = $ config [ 'name' ] ; } // Removes the array indication for select multiple $ relationship = str_replace ( '[]' , '' , $ relationship ) ; $ method = 'all' ; if ( ! is_object ( $ config [ 'config' ] [ 'model' ] ) ) { $ class = app ( ) -> make ( $ config [ 'config' ] [ 'model' ] ) ; } else { $ class = $ config [ 'config' ] [ 'model' ] ; } if ( isset ( $ config [ 'config' ] [ 'method' ] ) ) { $ method = $ config [ 'config' ] [ 'method' ] ; } if ( isset ( $ config [ 'config' ] [ 'params' ] ) ) { $ items = $ class -> $ method ( $ config [ 'config' ] [ 'params' ] ) ; } else { $ items = $ class -> $ method ( ) ; } if ( isset ( $ config [ 'config' ] [ 'nullable' ] ) && $ config [ 'config' ] [ 'nullable' ] === true ) { $ config [ 'config' ] [ 'options' ] [ '- Select -' ] = null ; } foreach ( $ items as $ item ) { $ config [ 'config' ] [ 'options' ] [ $ item -> $ label ] = $ item -> $ value ; } if ( ! isset ( $ config [ 'config' ] [ 'selected' ] ) ) { if ( ! isset ( $ config [ 'config' ] [ 'multiple' ] ) ) { $ selected = '' ; if ( is_object ( $ object ) && method_exists ( $ object , $ relationship ) ) { if ( $ object -> $ relationship ( ) -> first ( ) ) { $ selected = $ object -> $ relationship ( ) -> first ( ) -> $ value ; } } $ relationship = str_replace ( '_id' , '' , $ relationship ) ; if ( method_exists ( $ object , $ relationship ) ) { if ( $ object -> $ relationship ( ) -> first ( ) ) { $ selected = $ object -> $ relationship ( ) -> first ( ) -> $ value ; } } } else { $ selected = $ class -> $ method ( ) -> pluck ( $ value , $ label ) ; } } else { $ selected = $ config [ 'config' ] [ 'selected' ] ; } return $ this -> makeSelected ( $ config , $ selected , $ custom ) ; }
Make a relationship input.

@param array  $config
@param string $label
@param string $value
@param mixed $custom

@return string
Make a relationship input .