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.
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.
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