Laravel5怎么实现搜索分页能保留搜索条件
作者:
秒速五厘米
HTML代码
<form action="{{route('sousuo')}}" method="get"> @csrf <div class="col-lg-12" style="margin-top: 45px"> <div class="input-group xs-mb-15"> <input placeholder="输入搜索关键词" required="" type="text" class="form-control kuan1" name="key"> <span class="input-group-btn"> <button class="btn btn-info kuan2" type="submit">搜索</button> </span> </div> </div> </form>
路由代码
Route::get('sousuo','HomeController@sousuo')->name('sousuo');
PHP代码
public function sousuo(Request $request) { $key = $request->input('key'); $kun = Content::where('title','like','%'.$key.'%') ->orderBy('id', 'desc') ->paginate(5); $kun->withPath('/arcitle/sousuo?key='.$key); return View('index',compact('kun')); }