Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5搜索不起作用_Php_Laravel_Search_Laravel 5 - Fatal编程技术网

Php Laravel 5搜索不起作用

Php Laravel 5搜索不起作用,php,laravel,search,laravel-5,Php,Laravel,Search,Laravel 5,我是Laravel5.4的新手,需要创建多属性搜索。 在我搜索之前。 搜索后的结果与搜索前的结果相同。 这是我的控制器 public function search_code(Request $request){ $query = $request->search; $queryType = $request->institute; // 'id' or 'name' $items = DB::table('registerdetails');

我是Laravel5.4的新手,需要创建多属性搜索。 在我搜索之前。

搜索后的结果与搜索前的结果相同。

这是我的控制器

 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>

有人能建议我通过搜索此项来获得结果吗?

更改“选择”下拉列表中的值,如下所示

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

您面临的确切问题是什么?搜索不起作用。例如,如果我输入id 1,两个结果都会显示,但它们在两个不同的id中。它现在是否显示所有记录?是的,当然,这就是我说它不起作用的原因
<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>
if($queryType == 'id'){
  $items = $items->where('id', 'LIKE',"%$query%");
}
else if($queryType == 'full_name'){
  $items = $items->where('full_name', 'LIKE',"%$query%");
}