Laravel 5中URL中的标签

See*_*ore 2 php url laravel laravel-routing laravel-5

我有一个针对客户的搜索输入。客户有一个地址,例如,某些地址中包含数字符号#51 Scout Fuentebella。我在搜索中包括了地址。

我的路线:

Route::get('customer/search/{input}', 'CustomerController@search');
Run Code Online (Sandbox Code Playgroud)

每当我搜索他们的地址,例如localhost:8000 / customer / search /#51 Sc时,都会出现以下错误:

RouteCollection.php第161行中的NotFoundHttpException:

pat*_*cus 5

井号(#)在网址内部具有特殊含义。它标记片段标识符的开始,并且仅在客户端进行处理。之后的任何内容#都不会发送到服务器。

如果您的网址中需要包含哈希,则需要在构建网址之前对数据进行urlencode。

#编码为%23,因此对于您的示例来说localhost:8000/customer/search/%2351%20Sc应该可以正常工作。