分页搜索结果
我刚刚开始使用Laravel,我正在尝试使用适当的分页来创建搜索功能.该功能适用于第一页,但第二页则不适用.我认为它不会将结果提供给下一页,但我似乎无法找到答案.
public function search() { $q = Input::get('search'); # going to next page is not working yet $product = Product::where('naam','LIKE','%' . $q . '%') ->orWhere('beschrijving','%' . $q . '%') ->paginate(6); return view('pages.index',compact('product')); }
这是我的路线:
Route::post('search{page?}','IndexController@search');
这是第二页的网址:
/search?page=2
这是我展示我的分页的方式:
{{ $product->appends(Request::get('page'))->links()}}
错误:
MethodNotAllowedHttpException in RouteCollection.PHP line 218:
路线:
Route::get('search/{page?}','IndexController@search');
错误:
MethodNotAllowedHttpException in RouteCollection.PHP line 218: in RouteCollection.PHP line 218 at RouteCollection->methodNotAllowed(array('GET','HEAD')) in RouteCollection.PHP line 205 at RouteCollection->getRouteForMethods(object(Request),array('GET','HEAD')) in RouteCollection.PHP line 158 at RouteCollection->match(object(Request)) in Router.PHP line 780 at Router->findRoute(object(Request)) in Router.PHP line 610 at Router->dispatchToRoute(object(Request)) in Router.PHP line 596 at Router->dispatch(object(Request)) in Kernel.PHP line 267 at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.PHP line 53 at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.PHP line 46 at CheckForMaintenanceMode->handle(object(Request),object(Closure)) in Pipeline.PHP line 137 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.PHP line 33 at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.PHP line 104 at Pipeline->then(object(Closure)) in Kernel.PHP line 149 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.PHP line 116 at Kernel->handle(object(Request)) in index.PHP line 53
我希望我的问题清楚,格式正确.提前谢谢(抱歉我的英文不好)
回答:
我使用post函数进行初始搜索,并使用get函数进行后续页面.这是可能的,因为我现在正在搜索URL.
编辑: