Laravel 5中URL中的标签 [英] Hashtag in URL in Laravel 5

查看:55
本文介绍了Laravel 5中URL中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a search input for customers. The customers have an address, and some of the addresses contain the number sign, for example #51 Scout Fuentebella. I included address in my search.

我的路线:

Route::get('customer/search/{input}', 'CustomerController@search');

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

Whenever I search for their address like localhost:8000/customer/search/#51 Sc, I get the following error:

RouteCollection.php第161行中的

NotFoundHttpException:

NotFoundHttpException in RouteCollection.php line 161:

推荐答案

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

The hash mark (#) has special meaning inside of a url. It marks the start of the fragment identifier and is only handled on the client side. Nothing after the # will be sent to the server.

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

If your url needs to have a hash inside of it, then you need to urlencode the data before building the url.

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

# encodes to %23, so for your example, localhost:8000/customer/search/%2351%20Sc should work fine.

这篇关于Laravel 5中URL中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆