doujiao0110 2018-09-05 11:01
浏览 32

按钮按下显示隐藏表

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');
            }

        }
    }
  • 写回答

1条回答 默认 最新

  • dshtze500055 2018-09-05 13:32
    关注

    $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
    
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)