2017-04-17 20 views
0

私はlaravel 5.4の新機能で、マルチ属性検索を作成する必要があります。 i検索前に enter image description hereLaravel 5検索機能が無効になっています

前と同じ結果が検索された後。 enter image description here

ここは私のコントローラです。

public function search_code(Request $request){ 
    $query = $request->search; 
    $queryType = $request->institute; // 'id' or 'name' 
    $items = DB::table('registerdetails');   

    if($queryType == 'id'){ 
     $items = $items->where('id', 'LIKE',"%$query%"); 
    } 
    if($queryType == 'full_name'){ 
     $items = $items->where('full_name', 'LIKE',"%$query%"); 
    } 
    $items = $items->get(); 

    return view('registeredusers.index')->with('items',$items); 

      } 

ここは私の見解です。私が書いたルートで

<form action="search" method="post" class="form-inline">   
    <select name="institute" id="institute"> 
    <option selected="selected" value="Trainee Id">Trainee Id</option> 
    <option value="Trainee Name">Trainee Name</option> 
    <label for="Search">Name</label> 
</select> 
     <input type="text" name="search" /><br> 
     <input type="hidden" value="{{ csrf_token() }}" name="_token" /> 
     <input type="submit" name="submit" value="Search"> 
     </form> 

</div> 
</div> 
</div> 
      <div class="panel panel-default"> 

      <div class="panel-body"> 

        <table class="table table-striped"> 
        <thead> 

        <th>Full Name</th> 
        <th>Name with initials</th> 
        <th>National ID Number</th> 
        <th>Date Of Birth</th> 

        </thead> 

        <tbody> 
        @foreach($items as $item) 

        <tr> 

        <td>{{ $item->full_name }}</td> 
        <td>{{ $item->name_with_initials }}</td> 
        <td>{{ $item->nic_no }}</td> 
        <td>{{ $item->date_of_birth }}</td> 
       </tr> 
        @endforeach 

        </tbody> 

      </table> 

      </div> 
     </div> 

、私しかしここでの問題は、ルートにある2つの敗走

Route::group(['middleware' => ['web']], function() { 
    Route::resource('/userregister', 'UserRegisterController'); 

}); 
Route::post('search', '[email protected]_code'); 

は、誰もがこれを検索して結果を得るために私を提案することができますか?

<select name="institute" id="institute"> 
    <option selected="selected" value="id">Trainee Id</option> 
    <option value="full_name">Trainee Name</option> 
    <label for="Search">Name</label> 
</select> 

つ以上の提案、 以下のような選択のドロップダウンで

+0

使用しますあなたは直面している? –

+0

検索が動作していません。例id iを入力すると、両方の結果が表示されますが、2つの異なるIDになります – Dasun

+0

これですべてのレコードが表示されますか? – manian

答えて

0

変更値は1つの条件のみが可能である場合は、正確な問題であり、何を、以下のような「場合、他の」

if($queryType == 'id'){ 
    $items = $items->where('id', 'LIKE',"%$query%"); 
} 
else if($queryType == 'full_name'){ 
    $items = $items->where('full_name', 'LIKE',"%$query%"); 
} 
+0

ありがとうございますsir.itはうまく動作します:) – Dasun

+0

私はうまく働いています。ハッピーコーディング:) – manian

関連する問題