搜索表格Laravel

时间:2017-12-30 09:09:23

标签: php laravel

我有这个搜索功能,我试图让它看起来似乎不起作用..我有2个搜索功能,一个用于包含建筑物列表的主页面,另一个在每个页面上它包含办公室。主页面搜索工作但搜索办公室并不搜索主页面而不是页面上显示的页面。下面是搜索办公室的代码..问题是什么?

继承我的建筑搜索代码,这是有效的

-BuildingController.php

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

-buildings.blade.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()!!}

继承我的代码办公室搜索,这是行不通的

-OfficeController.php

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

-building.blade.php

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

2 个答案:

答案 0 :(得分:0)

Hello TeamPlar Jarj,

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

查看代码。它发出“ - &gt; get()”未添加

答案 1 :(得分:0)

  

office.blade.php(刀片文件)

{!! Form::open(['method'=> 'GET','url'=>'/office/search','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() !!}
  

web.php(路线)

Route::get('office/search', 'App\Http\Controllers\OfficeController@search');
  

OfficeController.php(Controller)

public function search(Request $request) {
    $searchoffice = $request->searchoffice;
    $offices = Office::where('name','like','%'.$searchoffice.'%')->get();

    $viewData = [
        'offices' => $offices,
    ];
    return view('office', $viewData);
}