Skip to content
Advertisement

How to pass `?` with url in laravel?

I am passing comments through the GET method, which contains special characters including ?. I am using the following code in route.

Route::get('CustRequest/{id}/{comment}', 'ApprovalController@CustomerRequest')->where('comment', '(.*)');

It working well for other special characters except for ?.

Advertisement

Answer

You should change ? from the URL to %3F which is URL encode for question mark(?).

The question mark is a part of URI generic syntax which consists of a hierarchical sequence of five components:

URI = scheme:[//authority]path[?query][#fragment]

The question mark is the generic syntax to separate path and query string and you can not change that syntax. So change the ? from the URL to %3F is a must.

Long text in the path is not best practice, you should change the comment from the path to query string, an example to domain/custrequest/id/?comment=blabla+http://dom.main/?ex=sss and get it from the controller as request()->comment you can get ? data after the first question mark.

another reference: What is a question mark in URL

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement