Laravel搜索表不起作用

时间:2018-01-01 01:52:26

标签: php laravel

我有两个搜索表单一个用于主页,另一个是其他页面。主页搜索表单搜索建筑物,而另一个搜索该页面中找到的办公室。

这里的主页搜索表单是代码

BuildingController.php

memcpy()

buildings.blade.php

  $search = \Request::get('search');
  $buildings = Building::where('name','like','%'.$search.'%')->orderBy('id', 'asc')->paginate();

  return view('buildings')->with('buildings', $buildings);

这是办公室的另一个搜索表单,无论何时点击搜索它都会重新定向回主页

OfficeController.php

 {!! Form::open(['method'=> 'GET','url'=>'/','role'=>'search']) !!}
       <div class="input-group col-xs-4 col-md-6" >
         <input type="text" name="search" class="form-control" placeholder="Search...">
             <span class="input-group-btn">
               <button type="submit" class="btn btn-info btn-md">Search</i>
              </button>
           </span>
       </div>
 {!! Form::close()!!}

building.blade.php

$searchoffice = \Request::get('searchoffice');
    $offices = Office::where('name','like','%'.$searchoffice.'%')->get();
    $data['building'] = $offices
    return view('$offices',$data);

路线

{!! Form::open(['method'=> 'GET','url'=>'/','role'=>'$searchoffice']) !!}
    <div class="input-group col-xs-4 col-md-6" >
      <input type="text" name="searchoffice" class="form-control" placeholder="Search...">
     <span class="input-group-btn">
       <button type="submit" class="btn btn-info btn-md">Search</i>
       </button>
      </span>
        </div>
         {!! Form::close()!!}

1 个答案:

答案 0 :(得分:0)

You're using the same method for both search forms. To fix that you should create a new route:

Route::get('searchoffice', 'OfficeController@index');

Where index is the method in OfficeController you've shown before.

And then use the route in the building.blade.php:

{!! Form::open(['method'=> 'GET','url'=>'/searchoffice', 'role'=>'$searchoffice']) !!}