Вставка нескольких строк в Laravel - PullRequest
0 голосов
/ 30 сентября 2019

Я пытаюсь вставить несколько строк в Laravel 5.8. Данные формы отправлены;однако он возвращает только одну строку вставленных данных.

Javascript для добавления каждой строки работает хорошо. Форма отправляется на правильный маршрут и выдает ошибку.

Argument 1 passed to Illuminate\Database\Eloquent\Builde:create() must be of the type array, string given, called in /home/emscomplete/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 1570

Возвращаются массивы: sc

array:1 [▼
  "index" => array:4 [▶]
]

abc     

array:1 [▼
  "index" => "09/23/2019"
]

Я ввел в форму две строки, каждая для$ sc и один для $ abc.

<form action="/application/store" method="POST" name="form-wizard" id="application" class="form-control-with-bg">

<!-- begin col-10 -->
<div class="col-xl-10">
    <legend class="no-border">Please enter any certificate issued by a state office.</legend>
    <!-- begin form-group -->
    <div class="form-group row offset-2">
        <table id="certification_table" align=center class="table table">
            <thead>
            <tr>
                <th>Issuing State</th>
                <th>Certificate Type</th>
                <th>Certificate Number</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody>

            </tbody>
            <tfoot>
    <tr>
      <td colspan="5" style="text-align: left;">
        <input type="button" class="btn btn-lg btn-block " id="addrow" value="Add Row" />
      </td>
    </tr>
    <tr>
    </tr>
  </tfoot>
        </table>

    </div>
    <!-- end form-group -->

</div>
<!-- end col-10 -->

<!-- begin col-10 -->
<div class="col-xl-10">
    <legend class="no-border">Please enter any ABC certificate you hold. For example this would be CPR, ACLS, PALS, ACLS ect.</legend>
    <!-- begin form-group -->
    <div class="form-group row offset-2">
        <table id="abc_table" align=center class="table table">
            <thead>
            <tr>
                <th>Certification Type</th>
                <th>Certificate Number</th>
                <th>Expiration</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody>

            </tbody>
            <tfoot>
            <tr>
                <td colspan="5" style="text-align: left;">
                    <input type="button" class="btn btn-lg btn-block " id="addrow2" value="Add Row" />
                </td>
            </tr>
            <tr>
            </tr>
            </tfoot>
        </table>

    </div>
    <!-- end form-group -->

</div>
<!-- end col-10 -->

<form>

<script>

    $(document).ready(function() {
        var counter = 0;

        $("#addrow").on("click", function() {
            var newRow = $("<tr>");
            var cols = "";

            cols += '<td><select name="sc[index][state]" id="state'+ counter +'" class="selectpicker" data-width="fit" data-style="btn-dark" data-parsley-group="step-2" data-parsley-required="true" title="Choose Issuing State"><option value="1">Ohio</option><option value="2">Kentucky</option><option value="3">West Virgina</option></select></td>';
            cols += '<td><select name="sc[index][certification_level]" id="certification'+ counter +'" class="selectpicker" data-width="fit" data-style="btn-dark" data-parsley-group="step-2" data-parsley-required="true" title="Choose Certification Type">@foreach($cert_level as $row)<option value="{{$row->id}}">{{$row->label}}</option>@endforeach</select></td>';
            cols += '<td><div class="md-form"><input type="text" class="form-control" name="sc[index][cert_number]" data-parsley-group="step-2" data-parsley-required="true" placeholder="Certification Number"></div></td>';
            cols += '<td><div class="input-group date md-form" data-provide="datepicker"><input type="text" name="sc[index][expiration]" placeholder="Expiration" data-parsley-group="step-2" data-parsley-required="true" class="form-control"><div class="input-group-addon"><span ><i class="fa fa-calendar-times"></i></span></div></div></td>'
            cols += '<td><input type="button" class="ibtnDel btn btn-md btn-danger"  value="Delete"></td>';
            newRow.append(cols);
            $("#certification_table").append(newRow);
            $('#state'+counter).selectpicker();
            $('#certification'+counter).selectpicker();
            counter++;
        });



        $("#certification_table").on("click", ".ibtnDel", function(event) {
            $(this).closest("tr").remove();
            counter -= 1
        });


    });


$(document).ready(function() {
    var counter = 0;

    $("#addrow2").on("click", function() {
        var newRow = $("<tr>");
        var cols = "";

    cols += '<td><select name="abc[index] [certification_type]" id="certification_type'+ counter +'" class="selectpicker" data-width="fit" data-style="btn-dark" data-parsley-group="step-3" data-parsley-required="true" title="Choose Issuing State">@foreach($certification as $id => $certification) <option value="{{$id}}" >{{$certification}}</option> @endforeach </select></td>';
    cols += '<td><div class="md-form"><input type="text" class="form-control" name="abc[index] [cert_number]" data-parsley-group="step-3" data-parsley-required="true" placeholder="Certification Number"></div></td>';
    cols += '<td><div class="input-group date md-form" data-provide="datepicker"><input type="text" name="abc[index] [expiration]" placeholder="Expiration" data-parsley-group="step-3" data-parsley-required="true" class="form-control"><div class="input-group-addon"><span ><i class="fa fa-calendar-times"></i></span></div></div></td>'
    cols += '<td><input type="button" class="ibtnDel btn btn-md btn-danger"  value="Delete"></td>';
    newRow.append(cols);
    $("#abc_table").append(newRow);
    $('#certification_type'+counter).selectpicker();
    counter++;
});



$("#abc_table").on("click", ".ibtnDel", function(event) {
    $(this).closest("tr").remove();
    counter -= 1
});


});

</script>

Контроллер

 foreach ($request->sc as $sc) {

                StateCertifications::create($sc);

            }

            //dd($request->abc);

            foreach ($request->abc as $abc) {

                EmployeeAbcCertification::create($abc);

            }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...