0

I am sending data in json format using postman to my server in Laravel 4.2,

{ "id_servicio" = "8", "user_token" = "3853656261737469616e3130" } 

to receive all infomation I use the Input::json()->all()method but this nothing recive and apper Error Undefined index: user_token error.

My code:

Route

Route::post('motoboy/service/finish/info', array('uses' => 'ServicioController@finishServicio')); 

Controller

function finishServicio(){ $input = Input::json()->all(); $token = $input['user_token']; // Error in this part $idServicio = $input['id_servicio']; $servicio = DB::table('servicios')->where('id_servicio', $idServicio)->first(); $motoboy = DB::table('motoboys')->where('auth_token', $token)->first(); if($motoboys != null){ if($servicio != null){ $array = array('Code' => '202', 'Message' => 'EL servicio existe y está listo para recibir las imagenes'); return Response::json($array); }else{ $array = array('Error' => 'Servicio no encontrada', 'Code' => '404', 'Message' => 'Servicio no encontrado'); return Response::json($array); } }else{ $array = array('Error' => 'Motoboy no autentificado', 'Code' => '401', 'Message' => 'Motoboy no autentificado'); return Response::json($array); } } 

When I use dd($input) function, return this array{0} How can I fix it?


Edit

I am sending information from Android app to my server in laravel. I am using GSON to send the information in JSON Format, for this reason I need to use Input::json()->all() because receive the input in JSON, if I use Input::all() and I send a JSOn, that method doesnt receive nothing

1

1 Answer 1

1

Change Input::json()->all(); to Input::all(); it should work.

Sign up to request clarification or add additional context in comments.

4 Comments

works but I am sending the information in JSON Format, any way to transform it?
you like to transform it, to what exactly?
I am sending information from Android app to my server in laravel. I am using GSONto send the information in JSON Format, for this reason I need to use Input::json()->all() because receive the input in JSON, if I use Input::all(); and I send a JSOn, that method doesnt receive nothing
You need to make sure you are passing the contentType: "application/json" in the request, then laravel is smart enough to recognize it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.