使用数组将数据从视图 (Blade) 传递到 laravel 中的控制器

Passing data using array from View (Blade) to Controller in laravel

我有一个 blade 表单,其中有一个转发器输入框和一个 select 框,转发器工作正常,但我如何将数据从这些字段传递到 back-end 控制器在 laravel?

add.balde.php

<!--begin::Add-Invoice-Form-->
<form class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" action="{{route('store_invoice')}}" method="POST" enctype="multipart/form-data">
    {{ csrf_field() }}
    <div class="m-portlet__body">
        <div class="form-group m-form__group row">

            <div class="col-lg-4">
                <label>
                    Customer Name:
                </label>
                <select class="form-control m-select2" id="m_select2_1" name="customerId">
                    @foreach($customer_list as $customer)
                        <option value=" {{ $customer->id }} ">
                        {{ $customer->fName }} {{ $customer->mName }} {{ $customer->lName }}
                        </option>
                    @endforeach  
                </select>
            </div>
            <div class="col-lg-4">
                <label>
                    Invoice Type:
                </label>
                <div class="m-radio-inline">
                    <label class="m-radio m-radio--solid">
                        <input type="radio" name="invoiceType" checked value="billable">
                        Billable
                        <span></span>
                    </label>
                    <label class="m-radio m-radio--solid">
                        <input type="radio" name="invoiceType" value="nonbillable">
                        Non Billable
                        <span></span>
                    </label>
                </div>
            </div>
        </div>

     <div id="m_repeater_1">

        <div class="form-group row" id="m_repeater_1">
            <div data-repeater-list="" class="col-lg-12">
                <div data-repeater-item class="form-group m-form__group row align-items-center">
                    <div class="col-lg-4">
                <label>
                    Summary Number:
                </label>
                <select class="form-control m-select2" id="m_select2_2" name="certificateId[]">
                    @foreach($certificate_list as $certificate)
                        <option value=" {{ $certificate->id }} ">
                        {{ $certificate->summary_no }} ( {{ $certificate->certificateType() }} )
                        </option>
                    @endforeach  
                </select>
            </div>
                    <div class="col-lg-3">
                                <label>
                                    Rate:
                                </label>
                                <input type="number" class="form-control m-input" name="rate" placeholder="Enter rate">
                    </div>
                    <div class="col-lg-3">
                        <br/>
                        <div data-repeater-delete="" class="btn btn btn-danger m-btn m-btn--icon">
                            <span>
                                <i class="la la-trash-o"></i>
                                <span>
                                    Remove
                                </span>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="m-form__group form-group row">
            <div class="col-lg-4">
                <div data-repeater-create="" class="btn btn btn-warning m-btn m-btn--icon">
                    <span>
                        <i class="la la-plus"></i>
                        <span>
                            Add
                        </span>
                    </span>
                </div>
            </div>
        </div></div>


    </div>

    <div class="m-portlet__foot m-portlet__no-border m-portlet__foot--fit">
        <div class="m-form__actions m-form__actions--solid">
            <div class="row">
                <div class="col-lg-4"></div>
                <div class="col-lg-8">
                    <button type="submit" class="btn btn-primary">
                        Submit
                    </button>
                    <button type="reset" class="btn btn-secondary">
                        Cancel
                    </button>
                </div>
            </div>
        </div>
    </div>
</form>
<!--end::Add-Invoice-Form-->

当使用中继器归档多个 select 框时,如何以数组格式发送值?This images shows the UI for the form

谢谢

你可以试试这个

 <input type="text" value="val" name="somename[]">
 <select name="someSelectName[]">
    <option value="value">select 1
    </option> 
 </select>

在服务器端,您将收到选定值作为具有给定名称的数组

改变你的

<div data-repeater-list="" class="col-lg-12">

<div data-repeater-list="arrayName" class="col-lg-12">

它应该可以工作。

这使得所有输入名称的数组格式为 arrayName[number][input] 并且每个输入的数字递增,最后在发送的请求中,您将在 arrayName[ 中获得所有输入=14=]