I am sending request via query parameters in laravel but this error is very uncommon to me as i have never seen this before what it actually does is it adds ?in very first key like this
array:1 [▼
"?name" => "google"
]
while hitting this url
http://travel.localhost/home?name=google
dd($_GET);
dd(request()->all());
dd(request()-get('name'));
i have done all these method but for first two lines i am getting
?name =
and for third line i am getting null as i am looking for name but request is ?name
as per my knowledge we use GET request frequently and bind required parameters in query parameter like ?param1=¶m2=¶m3 … and so on
so please anyone having any idea why this error occured or is anything wrong in my project
is this can be related to server as i am doing this on nginx but when i am using serve method
and serving my project on localhost:8000 then this problem is not there
any help
Thank you!!
3
Answers
Because get method pass parameter like that try using post method
Solution found on this link https://laracasts.com/discuss/channels/laravel/get-request-includes-question-mark-as-part-of-parameter-name?reply=448658
To get request paramters either its POST or GET use the
request()
helper for it.Example:
URL:
http://travel.localhost/home?name=google
Use
request()->get('name');
Result will begoogle
this can be used for post parameters as well.If you want to get all the request paramters
Use
request()->all()
Result will beAlso check your
appHttpKernel.php
file and see if you’re missing any middleware mentioned in below picture.This may be due to it is consider ? as a special char. If you could try below link?
http://travel.localhost/home?act=1&name=google