2017-07-24 53 views
1

電腦板如何通過輸入CNIC數量laravel顯示記錄

public function search() 
{ 
    $search=\Request::get('search'); 
    $needy=needAuth::where('cnic','like','%'.$search.'%')->orderBy('id')->paginate(30); 

    return view('needyStatus', compact('needy')); 
} 

查看

{!! Form::open(['method'=>'GET','url'=>'needyStatus','class'=>'navbar-form navbar-left','role'=>'search'])!!} 
    <div class="input-group custom-search-form"> 
    <input type="text" name="search" class="form-control"> 
    <span class="input-group-btn"> 
     <button type="submit" class="btn btn-default-sm"> 
     <i class="fa fa-search"></i> 
     </button> 
    </span> 
    </div> 
{!! Form::close() !!} 
</div> 
<tr> 
    <hidden> 
    @foreach($needy as $ned) 
    {{$ned->cnic}} 
    {{$ned->email}} 
    '{{$ned->firstName}} 
    @endforeach 
    </hidden> 
</tr> 

我進入CNIC它顯示了,但是當我刷新頁面顯示沒有輸入任何的所有數據cnic號碼。如何隱藏數據,並只顯示輸入cnic號碼顯示記錄?

回答

0

給這裏的條件:

public function search(){ 
    $search=\Request::get('search'); 
    if(isset($search)){ 
     $needy=needAuth::where('cnic','like','%'.$search.'%')->orderBy('id')->paginate(30); 
    } 
    return view('needyStatus', compact('needy')); 
} 
+0

不工作...取消定義變量$貧困。但我已經在控制器中聲明,當我把大括號顯示這個錯誤。 –

+0

如果條件返回視圖('needyStatus',compact('needy')); –