php – I cannot extract Json's information from Laravel

Question:

I get a request like this…

public function store(Request $request)
{
   return response()->json($request->all());
}

The way out is this:

anexoPdfGuia: {}

guiaFiscal: "{"empresas_id":"40","tributo_id":4,"mes_referencia":4,"vencimento":"2018-05-10","email":"carlos.boschin@gmail.com","titulo":"teste666","tributo":{"id":4,"nome":"PIS"},"mesReferencia":{"id":4,"nome":"Abril"},"data_vencimento":"2018-05-10T03:00:00.000Z","valor":1.11}"

I need to get an attribute inside the tax guide, but I'm not getting it with json_decode.

Can someone help me?

Answer:

With json_decode it should work, are you sure you are using it correctly?

Example:

$json = '{"empresas_id":"40","tributo_id":4,"mes_referencia":4,"vencimento":"2018-05-10","email":"carlos.boschin@gmail.com","titulo":"teste666","tributo":{"id":4,"nome":"PIS"},"mesReferencia":{"id":4,"nome":"Abril"},"data_vencimento":"2018-05-10T03:00:00.000Z","valor":1.11}';
$object = json_decode($json);
echo $object->empresas_id; // vai imprimir 40
Scroll to Top