错误未定义索引:当我使用Input :: json() - > all()方法时,Laravel中的user_token

时间:2022-10-17 09:29:54

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

我使用postman将数据以json格式发送到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.

接收所有信息我使用Input :: json() - > all()方法,但这没有recive和apper错误未定义索引:user_token错误。

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?

当我使用dd($ input)函数时,返回此数组{0}如何解决?


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

我正在通过laravel将Android应用程序中的信息发送到我的服务器。我使用GSON以JSON格式发送信息,因此我需要使用Input :: json() - > all()因为接收JSON中的输入,如果我使用Input :: all()并且我发送了一个JSOn,那种方法什么都不收

1 个解决方案

#1


1  

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

更改Input :: json() - > all(); to Input :: all();它应该工作。

#1


1  

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

更改Input :: json() - > all(); to Input :: all();它应该工作。