将传递值发布给Bootstrap Modal

时间:2019-07-04 05:30:19

标签: laravel bootstrap-modal

我遇到一个问题,即记录ID未传递到laravel项目中的Bootstrap模态

刀片表格视图

@foreach($Srequest as $r)
                    <tbody class = "text-center">
                        <td>
                            <button type="button" data-toggle="modal" data-target="#invoicepaymentModal" class = "addpayment btn btn-success btn-round" data-id="{{$r->id}}" ><i class ="fa fa-dollar"></i></button>
                        </td>
                        <td>{{$r->id}}</td>
                        <td>{{$r->memberrequest->last_name}}, {{$r->memberrequest->first_name}}</td>
                        <td>{{$r->invoice_number}}</td>
                        <td>{{$r->overview}}</td>
                        <td>${{$r->invoice_total}}</td>
                        <td>${{$r->requestpayment->sum('amount')}}</td>
                        <td class = "font-weight-bold">${{$r->invoice_total - $r->requestpayment->sum('amount')}}</td>
                        <td>{{$r->notes}}</td>
                    </tbody>
                    @endforeach

刀片模态视图(相同刀片)

<div class="modal fade" id="invoicepaymentModal" tabindex="-1" role="dialog" aria-labelledby="NewRollLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <h3 class="modal-title" id="editmemberModal">Invoice Payment</h3>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
                <p type="hidden" value=($Srequest as $r)></p>
            </button>
        </div>
        {!!Form::open(array('action' => ['SquadronAccountingController@payment'], 'method'=>'POST', 'class'=>'form-horizontal'))!!}
        <div class="modal-body">
           <h4>Payment for Request</h4>
            <div class="form-group">
                <label class="label-control">Invoice Number"</label>
                <div class="input-group">
                    <input type="text" class="form-control" name="id" id="idHolder">
                </div>
                    <label class="label-control">Payment Amount:</label>
                    <div class="input-group">
                        <input type="text" class="form-control" name="amount">
                    </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary btn-round" data-dismiss="modal">Close</button>
            <button type="submit" class="btn btn-primary btn-round">Save Changes</button>
        </div>
        {!!Form::close()!!}
    </div>
</div>

刀片式JavaScript

@section ('scripts')


<script>
  $("#invoicepaymentModal").on('show.bs.modal', function(e){
   var getID = $(e.relatedTarget).data('id');
   $("idHolder").val(getID);
 });

</script>
@stop

我面临的问题是将null值传递给控制器​​,这会导致数据库插入失败。

我希望从表中获取记录ID,并将其作为输入字段添加到数据库插入中。

0 个答案:

没有答案