laravel - 动态网址 laravel
问题描述
我有一个搜索城市地点的应用程序。
我有这条路线
Route::get('s/{where}/{places}', 'SearchController@places')->name('search');
搜索控制器
class SearchController extends Controller{
public function places(Request $request, $where, $places)
{
$where = $request->where;
if($places == 'places'){
return view('search.places', ['where' => $where]);
}else{
abort('404');
}
}
}
我也试过
->with()
要搜索的表单提交
<form action="{{ route('search' , ['where', 'places']) }}" method="get">
我得到这样的东西:
http://localhost/s/where/places?where=Paris
我想要的是
http://localhost/s/paris/places
当它应该替换 url 中的 where 而不是在问号后添加 where 时!
感谢帮助
解决方案
根据您设置路线的方式,您需要设置如下:
<form action="{{ route('search' , ['where' => 'paris', 'places' => 'places']) }}" method="get">
推荐阅读
- python - ModuleNotFoundError:没有名为“distutils”的模块
- node.js - 使用 Node/Express 解析 CSV 文件会吐出奇怪的 \x001 代码
- lua - 我正在尝试学习 ROBLOX lua 脚本,但有 1 个问题,我忘记了如何正确使用 Touch 事件
- php - 从深度数组 PHP 中检索值
- yum - 即使在设置 sslverify=false 之后,出现 Yum 错误“[Errno 14] 无法验证对等证书或对等证书无效”
- python - 将数组拆分为Python中的某个线程
- c# - 使用 c#/rest api 以编程方式重新启动 Service Fabric 节点
- python - 在 pandas 数据框中得到小于 1 个单位的点
- html - 如何在 bootstrap-vue 标签中设置单个字符的样式
- python - cdk8s 合成器的单独输出文件