[英]show hide table on button press
I've a search form where user enters data. 我有一个搜索表单,用户可以在其中输入数据。 On search button click, if the data is found, then only display the table tbl_paytable
else hide it. 在搜索按钮上单击,如果找到了数据,则仅显示表tbl_paytable
否则将其隐藏。
view page 查看页面
<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>
controller block 控制器块
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 is a laravel-collection, which has a method to check if it is empty. $ billsrch是一个laravel集合,它具有一种检查其是否为空的方法。
https://laravel.com/docs/5.6/collections#method-isnotempty https://laravel.com/docs/5.6/collections#method-isnotempty
@if($billsrch)
<div id="tbl_paytable">
// display table
</div>
@endif
Or just do the same as you did in your controller 或者只是像在控制器中一样做
@if(count($billsrch) > 0)
<div id="tbl_paytable">
// display table
</div>
@endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.