【发布时间】:2021-04-27 03:59:56
【问题描述】:
我有一个搜索城市地点的应用。
我有这条路线
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 时!
感谢您的帮助
【问题讨论】:
-
你的方法不对,试试这个
{{ route('search' , ['where' => 'France', 'places' => 'Paris']) }} -
感谢您的评论,但当我提交表单时,链接应该是动态的,如果是法国、巴黎或中国,我不知道!这就是为什么我发送位置,但在控制器中我想将用户更改为提交的城市位置
-
字段是动态的
{{ route('search' , ['where' => $countey, 'places' => $city]) }}希望你现在明白 -
在我没有定义 $countey 或 $city 的表单中?问题出在控制器而不是表单上!感谢您的帮助
-
where和places是可选参数吗?