skip to Main Content

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=&param2=&param3 … 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


  1. Because get method pass parameter like that try using post method

    Login or Signup to reply.
  2. 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 be google this can be used for post parameters as well.

    If you want to get all the request paramters
    Use request()->all() Result will be

    [
       'name' => 'google'
    ]
    

    Also check your appHttpKernel.php file and see if you’re missing any middleware mentioned in below picture.
    enter image description here

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search