| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 | <div class="box box-primary">    <div class="box-header with-border">        <h3 class="box-title">Scaffold</h3>    </div>    <!-- /.box-header -->    <div class="box-body">        <form method="post" action="{{$action}}" id="scaffold" pjax-container>            <div class="box-body">                <div class="form-horizontal">                <div class="form-group">                    <label for="inputTableName" class="col-sm-1 control-label">Table name</label>                    <div class="col-sm-4">                        <input type="text" name="table_name" class="form-control" id="inputTableName" placeholder="table name" value="{{ old('table_name') }}">                    </div>                    <span class="help-block hide" id="table-name-help">                        <i class="fa fa-info"></i>  Table name can't be empty!                    </span>                </div>                <div class="form-group">                    <label for="inputModelName" class="col-sm-1 control-label">Model</label>                    <div class="col-sm-4">                        <input type="text" name="model_name" class="form-control" id="inputModelName" placeholder="model" value="{{ old('model_name', "App\\Models\\") }}">                    </div>                </div>                <div class="form-group">                    <label for="inputControllerName" class="col-sm-1 control-label">Controller</label>                    <div class="col-sm-4">                        <input type="text" name="controller_name" class="form-control" id="inputControllerName" placeholder="controller" value="{{ old('controller_name', "App\\Admin\\Controllers\\") }}">                    </div>                </div>                <div class="form-group">                    <div class="col-sm-offset-1 col-sm-11">                        <div class="checkbox">                            <label>                                <input type="checkbox" checked value="migration" name="create[]" /> Create migration                            </label>                            <label>                                <input type="checkbox" checked value="model" name="create[]" /> Create model                            </label>                            <label>                                <input type="checkbox" checked value="controller" name="create[]" /> Create controller                            </label>                            <label>                                <input type="checkbox" checked value="migrate" name="create[]" /> Run migrate                            </label>                        </div>                    </div>                </div>                </div>                <hr />                <h4>Fields</h4>                <table class="table table-hover" id="table-fields">                    <tbody>                    <tr>                        <th style="width: 200px">Field name</th>                        <th>Type</th>                        <th>Size</th>                        <th>Nullable</th>                        <th>Key</th>                        <th>Default value</th>                        <th>Comment</th>                        <th>Action</th>                    </tr>                    @if(old('fields'))                        @foreach(old('fields') as $index => $field)                            <tr>                                <td>                                    <input type="text" name="fields[{{$index}}][name]" class="form-control" placeholder="field name" value="{{$field['name']}}" />                                </td>                                <td>                                    <select style="width: 200px" name="fields[{{$index}}][type]">                                        @foreach($dbTypes as $type)                                            <option value="{{ $type }}" {{$field['type'] == $type ? 'selected' : '' }}>{{$type}}</option>                                        @endforeach                                    </select>                                </td>                                <td><input type="number" class="form-control" placeholder="size" name="fields[{{$index}}][size]" value="{{$field['size']}}"/></td>                                <td><input type="checkbox" name="fields[{{$index}}][nullable]" {{ array_get($field, 'nullable') == 'on' ? 'checked': '' }}/></td>                                <td>                                    <select style="width: 150px" name="fields[{{$index}}][key]">                                        {{--<option value="primary">Primary</option>--}}                                        <option value="" {{$field['key'] == '' ? 'selected' : '' }}>NULL</option>                                        <option value="unique" {{$field['key'] == 'unique' ? 'selected' : '' }}>Unique</option>                                        <option value="index" {{$field['key'] == 'index' ? 'selected' : '' }}>Index</option>                                    </select>                                </td>                                <td><input type="text" class="form-control" placeholder="default value" name="fields[{{$index}}][default]" value="{{$field['default']}}"/></td>                                <td><input type="text" class="form-control" placeholder="comment" name="fields[{{$index}}][comment]" value="{{$field['comment']}}" /></td>                                <td><a class="btn btn-sm btn-danger table-field-remove"><i class="fa fa-trash"></i> remove</a></td>                            </tr>                        @endforeach                    @else                    <tr>                        <td>                            <input type="text" name="fields[0][name]" class="form-control" placeholder="field name" />                        </td>                        <td>                            <select style="width: 200px" name="fields[0][type]">                                @foreach($dbTypes as $type)                                    <option value="{{ $type }}">{{$type}}</option>                                @endforeach                            </select>                        </td>                        <td><input type="number" class="form-control" placeholder="size" name="fields[0][size]" value="0"></td>                        <td><input type="checkbox" name="fields[0][nullable]" /></td>                        <td>                            <select style="width: 150px" name="fields[0][key]">                                {{--<option value="primary">Primary</option>--}}                                <option value="" selected>NULL</option>                                <option value="unique">Unique</option>                                <option value="index">Index</option>                            </select>                        </td>                        <td><input type="text" class="form-control" placeholder="default value" name="fields[0][default]"></td>                        <td><input type="text" class="form-control" placeholder="comment" name="fields[0][comment]"></td>                        <td><a class="btn btn-sm btn-danger table-field-remove"><i class="fa fa-trash"></i> remove</a></td>                    </tr>                    @endif                    </tbody>                </table>                <hr style="margin-top: 0;"/>                <div class='form-inline margin' style="width: 100%">                    <div class='form-group'>                        <button type="button" class="btn btn-sm btn-success" id="add-table-field"><i class="fa fa-plus"></i>  Add field</button>                    </div>                    <div class='form-group pull-right' style="margin-right: 20px; margin-top: 5px;">                        <div class="checkbox">                            <label>                                <input type="checkbox" checked name="timestamps"> Created_at & Updated_at                            </label>                                                          <label>                                <input type="checkbox" name="soft_deletes"> Soft deletes                            </label>                        </div>                    </div>                    <div class="form-group pull-right" style="margin-right: 20px;">                        <label for="inputPrimaryKey">Primary key</label>                        <input type="text" name="primary_key" class="form-control" id="inputPrimaryKey" placeholder="Primary key" value="id" style="width: 100px;">                    </div>                </div>                {{--<hr />--}}                {{--<h4>Relations</h4>--}}                {{--<table class="table table-hover" id="model-relations">--}}                    {{--<tbody>--}}                    {{--<tr>--}}                        {{--<th style="width: 200px">Relation name</th>--}}                        {{--<th>Type</th>--}}                        {{--<th>Related model</th>--}}                        {{--<th>forignKey</th>--}}                        {{--<th>OtherKey</th>--}}                        {{--<th>With Pivot</th>--}}                        {{--<th>Action</th>--}}                    {{--</tr>--}}                    {{--</tbody>--}}                {{--</table>--}}                {{--<hr style="margin-top: 0;"/>--}}                {{--<div class='form-inline margin' style="width: 100%">--}}                    {{--<div class='form-group'>--}}                        {{--<button type="button" class="btn btn-sm btn-success" id="add-model-relation"><i class="fa fa-plus"></i>  Add relation</button>--}}                    {{--</div>--}}                {{--</div>--}}            </div>            <!-- /.box-body -->            <div class="box-footer">                <button type="submit" class="btn btn-info pull-right">submit</button>            </div>            {{ csrf_field() }}            <!-- /.box-footer -->        </form>    </div></div><template id="table-field-tpl">    <tr>        <td>            <input type="text" name="fields[__index__][name]" class="form-control" placeholder="field name" />        </td>        <td>            <select style="width: 200px" name="fields[__index__][type]">                @foreach($dbTypes as $type)                    <option value="{{ $type }}">{{$type}}</option>                @endforeach            </select>        </td>        <td><input type="number" class="form-control" placeholder="size" name="fields[__index__][size]" value="0"></td>        <td><input type="checkbox" name="fields[__index__][nullable]" /></td>        <td>            <select style="width: 150px" name="fields[__index__][key]">                <option value="" selected>NULL</option>                <option value="unique">Unique</option>                <option value="index">Index</option>            </select>        </td>        <td><input type="text" class="form-control" placeholder="default value" name="fields[__index__][default]"></td>        <td><input type="text" class="form-control" placeholder="comment" name="fields[__index__][comment]"></td>        <td><a class="btn btn-sm btn-danger table-field-remove"><i class="fa fa-trash"></i> remove</a></td>    </tr></template><template id="model-relation-tpl">    <tr>        <td><input type="text" class="form-control" placeholder="relation name" value=""></td>        <td>            <select style="width: 150px">                <option value="HasOne" selected>HasOne</option>                <option value="BelongsTo">BelongsTo</option>                <option value="HasMany">HasMany</option>                <option value="BelongsToMany">BelongsToMany</option>            </select>        </td>        <td><input type="text" class="form-control" placeholder="related model"></td>        <td><input type="text" class="form-control" placeholder="default value"></td>        <td><input type="text" class="form-control" placeholder="default value"></td>        <td><input type="checkbox" /></td>        <td><a class="btn btn-sm btn-danger model-relation-remove"><i class="fa fa-trash"></i> remove</a></td>    </tr></template><script>$(function () {    $('input[type=checkbox]').iCheck({checkboxClass:'icheckbox_minimal-blue'});    $('select').select2();    $('#add-table-field').click(function (event) {        $('#table-fields tbody').append($('#table-field-tpl').html().replace(/__index__/g, $('#table-fields tr').length - 1));        $('select').select2();        $('input[type=checkbox]').iCheck({checkboxClass:'icheckbox_minimal-blue'});    });    $('#table-fields').on('click', '.table-field-remove', function(event) {        $(event.target).closest('tr').remove();    });    $('#add-model-relation').click(function (event) {        $('#model-relations tbody').append($('#model-relation-tpl').html().replace(/__index__/g, $('#model-relations tr').length - 1));        $('select').select2();        $('input[type=checkbox]').iCheck({checkboxClass:'icheckbox_minimal-blue'});        relation_count++;    });    $('#model-relations').on('click', '.model-relation-remove', function(event) {        $(event.target).closest('tr').remove();    });    $('#scaffold').on('submit', function (event) {        //event.preventDefault();        if ($('#inputTableName').val() == '') {            $('#inputTableName').closest('.form-group').addClass('has-error');            $('#table-name-help').removeClass('hide');            return false;        }        return true;    });});</script>
 |