Laravel 如何将搜索结果更改为友好url
如何更改提交表单时生成的此URLLaravel 如何将搜索结果更改为友好url,laravel,forms,seo,Laravel,Forms,Seo,如何更改提交表单时生成的此URL http://localhost:8000/list_entreprise?activity=3&sub_category=1§eur=1&page=2 要访问此URL,请执行以下操作: http://localhost:8000/list_entreprise/category_name/sub_category_name/secteur_name/2 需要使URL对搜索引擎更友好 我从中的表单中的选择字段中获取类别、子类别
http://localhost:8000/list_entreprise?activity=3&sub_category=1§eur=1&page=2
要访问此URL,请执行以下操作:
http://localhost:8000/list_entreprise/category_name/sub_category_name/secteur_name/2
需要使URL对搜索引擎更友好
我从中的表单中的选择字段中获取类别、子类别和扇区
http://localhost:8000/list_entreprise
我的路线:
Route::get('/list_entreprise','App\Http\Controllers\SiteController@search')->name('search');
您需要在管线定义中指定这些组件
Route::get('/list_enterprise/{list_enterprise}/{category_name}/{sub_category_name}/{secteur_name}/{page?}',App\Http\Controllers\SiteController@search')->name('搜索')代码>
然后确保将这些作为参数添加到SiteController
中的search
方法中,即
公共函数搜索($listenerprise,$categoryName,$subCategoryName,$secteurName,$page=null){}
请注意页面
参数后的“?”,这表示它是URL的可选组件
在这里查看文档
当您为表单的操作指定路由时,您现在需要添加这些参数,以便它可以为您建立URL。抱歉,这并不能真正回答您的问题。要从选择框将这些值替换到表单提交中,您需要一个JavaScript解决方案,从表单中获取值并将其替换到表单提交到的URL中。不起作用@Andy[缺少[Route:search]的必需参数],但谢谢,你知道我如何使用Javascripor或其他方法来实现它吗