4
I will receive through the API a JSON with this structure:
{"leads": [{"id":"1", "email":"[email protected]", "name":"Bruno Ghisi", "company":"Resultados Digitais", "job_title":"IT", "bio":"This is my bio", "created_at":"2012-06-04T15:31:35-03:00", "opportunity":"false", "number_conversions":"3", "first_conversion": { "content": { "identificador":"ebook-abc", "nome":"Bruno", "email_lead":"[email protected]", "telefone":"99999999", "empresa":"Resultados Digitais", "cargo":"IT" }, "created_at":"2012-06-04T15:31:35-03:00", "cumulative_sum":"1", "source":"source 1" }, "last_conversion": { "content": { "identificador":"webinar-abc", "email_lead":"[email protected]" }, "created_at":"2012-06-04T15:31:35-03:00", "cumulative_sum":"2", "source":"source 2" } }] }
My API should receive this data and record in my database, I am starting the use of Laravel and followed a tutorial of Vedovelli, the API is receiving and recording Posts performed without being in json format but qnd will test in this format it inserts a line into the database recording only the ID without the other information.
My Controller is like this:
public function saveLead() { return Response::json($this->lead->saveLead(), 200); }
and Model in this way:
public function saveLead() { $input = Input::all(); //pega todos os dados do input $lead = new Lead(); //criar um novo registro $lead->fill($input); //inclui todos os dados do input $lead->save(); //salva o input return $lead; //retorna o lead gravado }
If I add a dd($input); it shows me an array with the data, but at the time of writing does not insert the values in the database.
From now on I thank those who can help me. :/
your bd structure is following the same return json? names including case-sensitives
– Tafarel Chicotti
From what I understand, in the same action of a controller you can receive a
request
both "normal" and JSON. Is that right? Your action has to be smart enough to know if the coming Request contains JSON or not?– humungs