[英]show hide table on button press
我有一個搜索表單,用戶可以在其中輸入數據。 在搜索按鈕上單擊,如果找到了數據,則僅顯示表tbl_paytable
否則將其隱藏。
查看頁面
<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 id="tbl_paytable">
// display table
</div>
控制器塊
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 view('pages.payBill', compact('billsrch'));
}
else
{
return view ( 'pages.payBill',compact('billsrch'))->with('alert-danger', 'Sorry No details found');
}
}
}
$ billsrch是一個laravel集合,它具有一種檢查其是否為空的方法。
https://laravel.com/docs/5.6/collections#method-isnotempty
@if($billsrch)
<div id="tbl_paytable">
// display table
</div>
@endif
或者只是像在控制器中一樣做
@if(count($billsrch) > 0)
<div id="tbl_paytable">
// display table
</div>
@endif
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.