Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahamed_sajeeb's avatar

$request->all() returns empty array for GET method laravel 5.5.

Currently I am using Laravel 5.5 for my current project. Now I am facing a strange problem. I have just upload my project on a nginx server which PHP Version => 7.0.24. While I am working on localhost (apache2 php version => 7.1.9) it works fine. But not my nginx server.

The problem is GET request. I have a form of method GET.

<form action="{{ route('test') }}" method="GET" >
    <input type="text" name="name">
    <input type="text" name="mobile">
    <input type="submit" value="Submit">                                
</form>

Here is my Route -

Route::get('test','SomeController@test')->name('test');

Here is SomeController's 'test' method-

public function test(Request $request){
    return $request->all();
}

It shows me all values when I run this 'test' route in localhost but it return empty array when I run it on the shared hosting nginx server. I cannot capture any problem. Please help somebody please.

0 likes
12 replies
PetarVukmanovic's avatar

Heya, I believe that Laravel now requires PHP 7.1+... Try to upgrade your PHP version to 7.1. Hopefully your shared hosting allows it.

sudo apt-get install -y python-software-properties
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update -y

Then (hope I got them all):

sudo apt-get install -y php7.1 php7.1-fpm php7.1-cli php7.1-common php7.1-mbstring php7.1-gd php7.1-intl php7.1-xml php7.1-mysql php7.1-mcrypt php7.1-zip

Next, open up Nginx config, by default, it should be in this file, if you've changed something, then it's in different (d-aaaah)

sudo vi /etc/nginx/sites-available/default

Under location ~ \.php$ block, change the fastcgi_pass to be 7.1:

fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;

Oh, and don't forget to set this bit in php.ini, it's commented by default:

cgi.fix_pathinfo=0

Your PHP files live in /etc/php/7.1/fpm.

Oh, if your shared hosting doesn't allow you to ssh, feel free to send them support ticket. Bug them 'till they upgrade to 7.1, or get a droplet in DigitalOcean and deploy over there with these steps I've made for you. Yeah. Right. Rock on. :)

Sorry for the long post, but hope it's helpful. ^_^

1 like
robrogers3's avatar

This is weird indeed. Try 2 things:

  • dump request('name');
  • dump request->input();
  • double check your headers [unlikely this is the problem, but verify the http side.]
Snapey's avatar

maybe something wrong with the url-rewrite not passing on the query string?

refynd's avatar

@ahamed_sajeeb did you ever get this resolved? I am having a similar issue where a route is returning an empty array.

rin4ik's avatar

@refynd open new discussion and describe your problem with your code and we can help :)

gayanov's avatar

I solved the problem with nginx:


   location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php$ {
        include /etc/nginx/fastcgi.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;

            try_files $uri =404;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

added in dir 'location / ' try_files $uri $uri/ /index.php?$query_string;

1 like
sumbria's avatar

Update nignx conf:

location / {
                try_files $uri $uri/ /index.php?$args;                
           }
munazzil's avatar

You have to avoid _token in your request->all().

Check this and see.

public function test(Request $request)

    {
    $data= $request->all();
   return $data;
   dd($data);
   }

And answer should be below one

  public function test(Request $request)
   
   {
    $data= $request->except('_token');
   return $data;
   }

Please or to participate in this conversation.