通过多个搜索框搜索不在laravel 5.3中工作

时间:2017-03-09 07:42:58

标签: html laravel-5

我目前正在使用两个搜索框进行多次搜索,一个是多列搜索框,另一个是选择框。

以下是我的搜索框html代码

<form action="{{ url('/admin/managestudent') }}" method="GET" files="false" id="filter-action">
    <table class="" style="margin-bottom: 0;">
        <tr class="">
            <td class="search-boxes"><input type="text" class="form-control" name="q" placeholder="Search" value="{{ \Request::input('q') }}"></td>
            <td class="search-boxes"><select class="form-control" name="r">
                <option value="">-Select learning mode-</option>
                <option value="1" <?php echo (\Request::input('r') == "1" ) ? 'selected' : '' ; ?>>Online</option>
                <option value="0" <?php echo (\Request::input('r') == "0" ) ? 'selected' : '' ; ?>>Offline</option>
            </select></td>
            <td width="80px"><label>&nbsp;&nbsp;</label><input type="submit" class="btn btn-success searchsubmit"></td>
            <td width="80px"><label>&nbsp;</label><a href="{{ url('/admin/managestudent') }}" class="btn btn-default" href="">Reset</a></td>
        </tr>
   </table> 
</form>

以下是我在控制器中搜索的功能

public function viewStudent(Request $request) {
    $getStudents = DB::table('student');
    $searchStudent = $request->input('q');
    $searchMode = $request->input('r');
    if (isset($searchMode)) {
        $getStudents->where("learning_mode", $searchMode);
    }
    if (isset($searchStudent)) {
        $getStudents->where("registration_no", "LIKE","%$searchStudent%")
                ->orWhere("enrollment_no", "LIKE", "%$searchStudent%")
                ->orWhere("firstname", "LIKE", "%$searchStudent%")
                ->orWhere("email", "LIKE", "%$searchStudent%")
                ->orWhere("mobile_no", "LIKE", "%$searchStudent%")
                ->orWhere("city", "LIKE", "%$searchStudent%");
    }
    return view('admin.student.grid')->with(['students' => $getStudents->orderBy('id', 'DESC')->paginate(15),'breadcrumb' => array()]);
}

我躲在里面的问题

  

if(isset($ searchStudent)){

然后$ searchMode(按选择框搜索)正在工作,否则它无法正常工作,但我可以使用第一个文本框进行搜索,无论如何。

0 个答案:

没有答案