Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 would 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?

like image 547
Benubird Avatar asked Feb 24 '14 15:02

Benubird


People also ask

How can get data from database in laravel?

After configuring the database, we can retrieve the records using the DB facade with select method. The syntax of select method is as shown in the following table. Run a select statement against the database.

What are form requests in laravel?

Form requests are custom request classes that encapsulate their own validation and authorization logic. A new StoreUserRequest class will be generated under "\App\Http\Requests" namespace containing a rules() & authorize() methods.

What is input function in laravel?

input() is a method of the Laravel Request class that is extending Symfony Request class, and it supports dot notation to access nested data (like $name = $request->input('products.0.name') ).


1 Answers

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: http://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Request.html#method_getContent

like image 131
Benubird Avatar answered Sep 16 '22 15:09

Benubird