answer status = 200 with Laravel

0

After receiving data from a URL in the form of json, I must respond with status [acknowledgment] (ACK 200) so that it does not continue to send the notification.  this is the function:

public function tryNotification(Request $request) {


    //recibimos la notificacion y la procesamos
    $request = json_decode($request);
    //guardamos la notificacion en la BD
    $saveNotification = new Notifications();
    $saveNotification->seller_id = $request->user_id;
    $saveNotification->resource = $request->resource;
    $saveNotification->topic = $request->topic;
    $saveNotification->received = $request->received;
    $saveNotification->save();
    //envia mensaje de RECIBIDO a Meli
    //aqui necesito la ayuda de como enviar respuesta de recibido al servidor
    //retorna datos guardados en la BD
    return response()->json($saveNotification);

}
    
asked by Ronel Jimenez 30.10.2017 в 16:26
source

2 answers

0

Ok, To place a code in the header of your answer, that is placed as the second parameter of the JSON response.

//response()->json(object,code_status)

return response()->json(Array,911);

The documentation does not show it , but you can (I use it )

    
answered by 30.10.2017 в 17:59
0
Siguiendo tu código puedes usarlo al pie de la letra solo agregando un segundo parámetro a tu línea del return

public function tryNotification(Request $request) {
    //recibimos la notificacion y la procesamos
    $request = json_decode($request);
    //guardamos la notificacion en la BD
    $saveNotification = new Notifications();
    $saveNotification->seller_id = $request->user_id;
    $saveNotification->resource = $request->resource;
    $saveNotification->topic = $request->topic;
    $saveNotification->received = $request->received;
    $saveNotification->save();
    //envia mensaje de RECIBIDO a Meli
    //aqui necesito la ayuda de como enviar respuesta de recibido al servidor
    //retorna datos guardados en la BD
    //Puedes pasar el estado que deseas en este caso use el 201 para ejemplificar el empleo del segundo parametro
    return response()->json($saveNotification, 201);

}
    
answered by 30.10.2017 в 18:38