Example #1
0
    public function VueformType(Field $field)
    {
        $asterix = '';
        if ($field->isRequired()) {
            $asterix = '<span class="text-danger">*</span>';
        }
        $toReturn = '

            <div class="form-group ' . $field->name . '">
                <div class="col-md-12 col-sm-12 ">
                <label for="' . $field->name . '" class="col-sm-2 control-label">' . $field->label . ' ' . $asterix . '</label>
                <div class="col-sm-10 "> ' . "\n";
        $has_relation = false;
        foreach ($field->relations as $relation) {
            if (in_array($relation->pivot->laravel_name, ['belongsTo'])) {
                $has_relation = true;
                $related_model = \App\Field::find($relation->pivot->to_field_id)->table;
                $toReturn .= '

                    <div v-if="!showForm_' . $related_model->variable . '">
                        <select v-model="object.' . $field->name . '" class="form-control" ' . $field->vueValidateField() . '>
                            <option v-for="' . $related_model->model . ' in ' . $related_model->model . 'List" :value="' . $related_model->model . '.' . $related_model->primary() . '"> ';
                foreach ($related_model->fields()->where('is_on_foreign_label', 1)->orderBy('order', 'asc')->get() as $foreignLabel) {
                    $toReturn .= '
                                    {{ ' . $related_model->model . '.' . $foreignLabel->name . ' }} ';
                }
                $toReturn .= '
                            </option>
                        </select>
                        ';
                if ($field->hasValidation()) {
                    $toReturn .= '
                        <div class="errors">
                            ' . $field->vueValidationErrors() . '
                        </div>
                    </div>' . "\n";
                }
                $toReturn .= '
                        <div v-else>
                            <input type="text" v-model="created' . $related_model->model . '.' . $related_model->primary() . '"  v-validate:' . $field->vueValidationVariable() . '="{required:true}">
                        </div>';
                // $toReturn.="<a target='_blank' class='pull-right btn btn-sm btn-success' href='{{route('".$basePath.".create')}}'><i class='fa fa-plus'></i> Create a ".$related_model->variable."</a>"."\n";
                $toReturn .= '
                    <ui-icon-button v-if="!showForm_' . $related_model->variable . '" icon="add" @click.prevent="showForm_' . $related_model->variable . '= ! showForm_' . $related_model->variable . ', this.object.' . $related_model->variable . '_id=\'\'" tooltip="Add" type="normal" color="primary" class="pull-right" ></ui-icon-button>

                    <ui-icon-button v-if="showForm_' . $related_model->variable . '" icon="remove" @click.prevent="showForm_' . $related_model->variable . '= ! showForm_' . $related_model->variable . '" tooltip="cancel" type="normal" color="default" class="pull-right" ></ui-icon-button>

                    <div class="well" v-if="showForm_' . $related_model->variable . '">

                        <div v-if="created' . $related_model->model . '.' . $related_model->primary() . '">' . "\n";
                $toReturn .= $this->tab7 . '<b>';
                foreach ($related_model->fields()->where('is_on_foreign_label', 1)->orderBy('order', 'asc')->get() as $foreignLabel) {
                    $toReturn .= '
                                {{ created' . $related_model->model . '.' . $foreignLabel->name . ' }} ';
                }
                $toReturn .= '
                            </b>

                        </div>
                        <div v-else>
                            <' . $related_model->VueTag('form') . ' force-mode="create" :created-object.sync="created' . $related_model->model . '" ></' . $related_model->VueTag('form') . '>
                        </div>
                    </div>
                    ' . "\n";
                //:created-id.sync="object[\''.$field->name.'\']"
            } elseif ($relation->pivot->laravel_name == 'belongsToMany') {
                $has_relation = true;
                $related_model = \App\Table::find($relation->pivot->to_model);
            }
        }
        if (!$has_relation) {
            $toReturn .= "\t\t";
            switch ($field->type->name) {
                case 'integer':
                case 'decimal':
                case 'bigint':
                    $toReturn .= '
                    <input type="number" class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'string':
                    $toReturn .= '
                    <input type="text" class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'password':
                    $toReturn .= '
                    <input type="password" class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'email':
                    $toReturn .= '
                    <input type="email" class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'currency':
                    $toReturn .= '<input type="date" class="form-control datepicker" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                <div class="errors">
                    ' . $field->vueValidationErrors() . '
                </div>' . "\n";
                    }
                    break;
                case 'dateTime':
                case 'datetime':
                case 'time':
                case 'date':
                    $toReturn .= '<input type="date" class="form-control datepicker" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'text':
                case 'mediumtext':
                case 'longtext':
                    $toReturn .= '
                    <textarea class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '></textarea>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'binary':
                    $toReturn .= '
                    <textarea class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '></textarea>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'boolean':
                    $toReturn .= '
                    <!--
                    <label class="radio-inline">
                        <input v-model="object.' . $field->name . '" type="radio" value="1"> Yes
                    </label>
                    <label class="radio-inline">
                        <input v-model="object.' . $field->name . '" type="radio" value="0"> No
                    </label>-->

                    <ui-switch :value.sync="object.' . $field->name . '" label="" ></ui-switch>
                        ';
                    break;
            }
        }
        // $toReturn.=" </div><p class='text-danger'>@if (\$errors->has('".$field->name."')) <span class='error'>{{ \$errors->first('".$field->name."') }}</span> @endif</p></div> "."\n\n";
        $toReturn .= '
                </div>
            </div>
        </div>
    ' . "\n\n";
        return $toReturn;
    }