如何更改通过提交表单生成的此 URL
http://localhost:8000/list_entreprise?activity=3&sub_category=1§eur=1&page=2
到这个网址: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_entreprise/{list_entreprise}/{category_name}/{sub_category_name}/{secteur_name}/{page?}','App\Http\Controllers\SiteController@search')->name('search');
然后一定要把这些作为参数添加到search
SiteController
中的方法, IE。public function search($listEnterprise, $categoryName, $subCategoryName, $secteurName, $page = null){}
请注意“?”后 page
参数,这表明它是 URL 的可选组件。
在此处查看文档 https://laravel.com/docs/8.x/routing#route-parameters .
当您为表单的操作指定路由时,您现在需要添加这些参数,以便它可以为您构建 URL。
关于laravel - 如何将搜索结果更改为友好的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66749600/