title: Laravel REST API request object is empty
body: <h1>Environment</h1>
  <p>I created an application using Laravel 5.7 and implemented a REST API. I have a route in routes/api.php that triggers a middleware which checks if the incoming request has a parameter called api_token.</p>
  <p><strong>This is a production environment and here are the specifics:</strong></p>
  <ul>
  <li>Linux Ubuntu 18.04 LTS 64-bit</li>
  <li>nginx/1.14.0</li>
  <li>Laravel 5.7</li>
  <li>PHP 7.2</li>
  </ul>
  <p>APP_ENV in the .env file is set to 'production' and APP_DEBUG is set to 'false'.</p>
  <h1>Problem</h1>
  <p>My problem is that the incoming request object is always empty when it arrives at the server. At least that's what my Laravel application says.</p>
  <p><strong>These are my routes in routes/api.php:</strong></p>
  <pre><code>Route::middleware('rest')-&gt;group(function() {
      Route::get('device-location/{deviceID}', 'PositionDataController@getDeviceLocation');
      Route::get('device-location/all', 'PositionDataController@getAllLocations');
      Route::post('device-location', 'PositionDataController@storeDeviceLocation');
      Route::put('device-location/{deviceID}', 'PositionDataController@updateDeviceLocation');
      Route::delete('device-location/{deviceID}', 'PositionDataController@deleteDeviceLocation');
  });
  </code></pre>
  <p>The routes are in a middleware group called 'rest' as you can see. I'm using the Route::get('device-location/{deviceID}', 'PositionDataController@getDeviceLocation'); route to test the functionality.</p>
  <p><strong>Here's the code from the middleware:</strong></p>
  <pre><code>public function handle($request, Closure $next)
  {
      if(request()-&gt;all()) {
          $deviceID = request()-&gt;device_id;
      }
      else {
          return response()-&gt;json([
              'error' =&gt; 'The request object is empty.',
              'request' =&gt; request(),
              'parameters' =&gt; request()-&gt;all(),
              'content' =&gt; request()-&gt;getContent(),
              'input' =&gt; request()-&gt;input()
          ], 500);
      }
  
      $device = MobileDevice::where('device_id', $deviceID)-&gt;first();
  
      if($device) {
          $deviceToken = $device-&gt;api_token;
          if($deviceToken == request()-&gt;api_token) {
              return $next($request);
          }
          else {
              return response()-&gt;json(['error' =&gt; 'Token does not match.'], 500);
          }
      }
      else {
          return response()-&gt;json(['error' =&gt; 'The device with the id [' . $deviceID . '] could not be found.'], 500);
      }
  }
  </code></pre>
  <p>The middleware first checks if there are parameters in the request object and then does some logic to check if the right token was sent. If the request object is empty it returns some data to help me understand what went wrong.</p>
  <p>I use Postman (<a href="https://www.getpostman.com" rel="nofollow noreferrer">https://www.getpostman.com</a>) to test the API. Here's my Postman setup:</p>
  <p><strong>Postman setup</strong></p>
  <p><img src="https://i.stack.imgur.com/9BoEp.png" alt="Screen Shot" /></p>
  <p><strong>Postman headers</strong></p>
  <p><img src="https://i.stack.imgur.com/MkI7O.png" alt="Screen Shot" /></p>
  <p><strong>This is the response I get in Postman:</strong></p>
  <p><strong>Postman response</strong></p>
  <p><img src="https://i.stack.imgur.com/1NCLD.png" alt="Screen Shot" /></p>
  <p>I get the same result if I call that route in a browser.
  Regardless of if I put in parameters or not the request seems to be always empty.</p>
  <p><strong>Here are the things that I've tried to do:</strong></p>
  <ul>
  <li>Not using the middleware</li>
  <li>Using the $request variable instead of the helper request()</li>
  <li>Switching between 'application/json' and 'application/x-www-form-urlencoded' in the Headers of my Postman setup</li>
  <li>Calling that route in a browser</li>
  <li>Updating to Laravel 5.7</li>
  </ul>
  <p>The strange thing is that all of this works perfectly on my local environment and on a test server that has the same specs as the production server.</p>
  <p><strong>UPDATE 01:</strong></p>
  <p>So it seems to be even worse...</p>
  <p>If I add a route like this in web.php:</p>
  <pre><code>Route::get('/request-return', function() {
      return request()-&gt;all();
  });
  </code></pre>
  <p>and visit that route like this:</p>
  <pre><code>laravel.application/request-return?device_id=1&amp;api_token=XgkQLs8G7OYTqdwsXmjJT5G9bxv20DRi
  </code></pre>
  <p>I get back an empty array [].</p>
  <p>So it seems like the parameters don't get to the server itself.</p>