我有一个搜索表单,用户可以在其中输入数据。在搜索按钮上单击,如果找到了数据,则仅显示表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');
}
}
}
答案 0 :(得分:0)
$ 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