我已经制作了一个用于搜索帐单号的表格。在数据库表中找到帐单后,数据应显示在标签中。我怎样才能做到这一点?然后,用户按下按钮以支付账单金额。
视图块
<form class="form-horizontal" method="POST" action="{{action('OrderedBookController@billPay')}}" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="row" style="padding-left: 1%;">
<div class="col-md-4">
<div class="form-group">
<label>Bill Number</label><span class="required">*</span>
<input type="text" maxlength="15" required="required" autofocus="autofocus" autocomplete="off" name="NBillNumber" class="form-control"/>
</div>
</div>
<div class="col-md-4">
<div class="form-group"></div>
<div class="form-group" style="padding-left: 5%;">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</div>
</div>
</form>
<div class="row" style="padding-left: 1%;">
<div class="col-md-4">
<div class="form-group">
<label>Book ID</label>
<output name="NBookID" class="form-control" aria-readonly="true"/>
</div>
<div class="form-group">
<label>Billed Date</label>
<output name="NBilledDate" class="form-control" aria-readonly="true"/>
</div>
</div>
<div class="col-md-4" style="padding-left: 3%;">
<div class="form-group">
<label>Billed Number</label>
<output name="NBilledNumber" class="form-control" aria-readonly="true"/>
</div>
<div class="form-group">
<label>Quantity</label>
<output name="NBilledQuantity" class="form-control" aria-readonly="true"/>
</div>
</div>
<div class="col-md-4"style="padding-left: 3%;">
<div class="form-group">
<label>Price</label>
<output name="NBilledPrice" class="form-control" aria-readonly="true"/>
</div>
<div class="form-group">
<label>Remarks</label>
<output name="NBilledRemarks" class="form-control" aria-readonly="true"/>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">PAY</button>
</div>
</div>
</div>
OrderedBookController代码块
public function searchBill()
{
return view ( 'pages.payBill');
}
public function billPay(Request $request)
{
$billNum = $request->input('NBillNumber');
if($billNum != ""){
$billsrch = OrderedBook::where ( 'BilledNum', $billNum )->get ();
if (count ( $billsrch ) > 0)
{
return response()->json($billsrch);
return view('pages.payBill', compact('billsrch'));
}
else
{
return view ( 'pages.payBill',compact('billsrch'))->with('alert-danger', 'Sorry No details found');
}
}
}
在调试billPay
方法时,我正在从数据库中获取数据。然后如何在我的视图块中显示数据。在以前的表格中,我将数据显示在表格中,但是现在我需要在表格中显示数据,并在按下按钮PAY
时更新付费列。我该怎么办?
路线代码块
Route::get('/billSearch','OrderedBookController@searchBill');
Route::post('/billPay','OrderedBookController@billPay');
答案 0 :(得分:1)
您必须基于这样的条件显示html。 如果您的表单是post方法,则应通过ajax处理。 如果您的表单是get方法,只需输入这样的条件即可。
@if ($billsrch)
<form class="form-horizontal" method="POST" action="{{action('OrderedBookController@billPay')}}" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="row" style="padding-left: 1%;">
<div class="col-md-4">
<div class="form-group">
<label>Bill Number</label><span class="required">*</span>
<input type="text" maxlength="15" required="required" autofocus="autofocus" autocomplete="off" name="NBillNumber" class="form-control"/>
</div>
</div>
<div class="col-md-4">
<div class="form-group"></div>
<div class="form-group" style="padding-left: 5%;">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</div>
</div>
</form>
<div class="row" style="padding-left: 1%;">
<div class="col-md-4">
<div class="form-group">
<label>Book ID</label>
<output name="NBookID" class="form-control" aria-readonly="true"/>
</div>
<div class="form-group">
<label>Billed Date</label>
<output name="NBilledDate" class="form-control" aria-readonly="true"/>
</div>
</div>
<div class="col-md-4" style="padding-left: 3%;">
<div class="form-group">
<label>Billed Number</label>
<output name="NBilledNumber" class="form-control" aria-readonly="true"/>
</div>
<div class="form-group">
<label>Quantity</label>
<output name="NBilledQuantity" class="form-control" aria-readonly="true"/>
</div>
</div>
<div class="col-md-4"style="padding-left: 3%;">
<div class="form-group">
<label>Price</label>
<output name="NBilledPrice" class="form-control" aria-readonly="true"/>
</div>
<div class="form-group">
<label>Remarks</label>
<output name="NBilledRemarks" class="form-control" aria-readonly="true"/>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">PAY</button>
</div>
</div>
</div>
@endif