我有这个搜索功能,我试图想它似乎不工作..我有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>
你好TeamPlar Jarj,
$searchoffice = \Request::get('searchoffice');
$offices = Office::where('name','like','%'.$searchoffice.'%')->get();
$data['offices'] = $offices
return view('$offices',$data);
看到代码。它没有添加“ - > get()”
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(控制器)
public function search(Request $request) {
$searchoffice = $request->searchoffice;
$offices = Office::where('name','like','%'.$searchoffice.'%')->get();
$viewData = [
'offices' => $offices,
];
return view('office', $viewData);
}