我正在尝试针对Laravel项目的发票创建付款方式。 这个想法是,当用户单击每个记录旁边的付款图标时,可以根据该记录记录付款。
我正在显示一种模式,用户可以在其中输入付款金额。
但是,我面临的问题是,无论我选择哪个记录,最后一个记录ID都是要输入到数据库中的ID
我创建了HTML视图和控制器处理代码,除了错误的ID之外,它们都可以正常工作
HTML视图-表格
<div class="card-body">
<table class="table">
<thead class="text-primary text-center">
<th width="5%"></th>
<th>Squadron Request No:</th>
<th>Name</th>
<th width="10%">Invoice Number</th>
<th>Overview</th>
<th width="10%">Total Amount</th>
<th width="10%">Payments</th>
<th width="10%">Balance</th>
<th>Notes</th>
</thead>
@foreach($Srequest as $r)
<tbody class="text-center">
<td>
<a href="" data-toggle="modal" data-target="#invoicepaymentModal" onclick="" class="btn btn-success btn-round"><i class="fa fa-dollar"></i></a>
</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
</table>
HTML模式
<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">×</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: {{ $r->id}} </h4>
<div class="form-group">
<input type="hidden" name="id" value="{{$r->id}}">
<input type="hidden" name="member_id" value="{{$r->member_id}}">
<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>
</div>
控制器
public function requested()
{
$Srequest = Srequest::where('complete', '=', 'N')->get();
$members = Member::where('active', '!=', 'N')->where('member_type', '=', 'League')->get();
return view('accounting.requestview', compact('Srequest', 'members'));
}
public function payment(Request $request)
{
$rollid = Rollmapping::latest()->value('id');
$e = new Requestpayment();
$e->request_id = $request->get('id');
$e->roll_id = $rollid;
$e->amount = $request->get('amount');
$e->save();
Alert::Success('Payement Recored')->autoclose(2000);
return redirect(action('SquadronAccountingController@requested'));
}
表格-付款
|ID|Request_ID|Amount|
表格-请求
|ID|Member_ID|Invoice_Number|Invoice_amount|Overview|Completed|Notes|
我想将表中记录的ID传递给Modal,以便在DB中记录正确的ID。请求表中的ID需要输入Request_ID