How do I get raw form data in laravel?

I have a script that is trying to send data to my site using HTTP PUT. Normally, I woudl just retrieve it by reading from the input stream with file_get_contents('php://input'). However, when I try that with laravel, I don't get anything! Why not? How do I read the raw input data?


Laravel intercepts all input. If you're using PHP prior to 5.6, the php://input stream can only be read once. This means that you need to get the data from the framework. You can do this by accessing the getContent method on the Request instance, like this:

$content = Request::getContent(); // Using Request facade
     /* or */ 
$content = $request->getContent(); // If you already have a Request instance
                                   // lying around, from say the controller  

Since Illuminate\Request extends Symfony\Component\HttpFoundation\Request, and getContent is defined here:

You can also use Request::json($key, $default); to return the value of a specific key in the json payload.

Update for latest Laravel (I'm using laravel 5.8), you may encounter error when using Request::getContent(); because the latest Symfony Request module (which underlie Laravel's Request module) no longer provide getContent as static method. Instead I use Request::createFromGlobals()->getContent();.


Need Your Help

Resampling of two data sets of different length in MATLAB

matlab signal-processing sampling resampling

I have two vectors: sensorA of length 927 and sensorB of length 1250. I would like to make them of the same length. The resample() function in MATLAB is very noisy at the edges and I need atleast

Behaviour of ResultSet after connection got corrupted

java sql jdbc resultset

Suppose I'm making a JDBC call and I had fetched data from a database to a ResultSet. But due to a network issue I lost my connection with the database.