我正在尝试制作搜索栏。问题是,这不会给我任何结果。
这是我的控制器:
public function results(Request $request)
{
$results = User::whereHas(function($query) use ($request){
if(($id = $request->get("id"))){
$query->where("id", $id);
}
if(($term = $request->get('term'))){
$query->where('name','like','%'.$term.'%');
}
});
}
这是我的路线:
Route::get('/results', 'UserController@results')->name('results.index');
以下是我的观点:
{!! Form::open([ ['route'=>'results.index'],'method'=>'GET', 'role'=>'search','action'=>'UserController@results']) !!}
<div class="input-group">
{!! Form::text('term',Request::get('term'),['class'=>'form-control', 'placeholder'=>'Search...']) !!}
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
{!! Form::close() !!}
提前致谢!