首页 > 解决方案 > 动态网址 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 时!

感谢帮助

标签: laravelurlroutes

解决方案


根据您设置路线的方式,您需要设置如下:

<form action="{{ route('search' ,  ['where' => 'paris', 'places' => 'places']) }}" method="get">

推荐阅读