Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PersonalHomePage's avatar

how should this look in a request

I have this snippet of code that uses $request->token->item_id and I'm trying to see what the value of it is, but I think I'm sending in the request incorrectly. I'm sending it to my end point as a json like so

{
	"testing": 123,
	"token": {
		"item_id": 456
	}
}

and I keep getting Trying to get property 'item_id' of non-object. How should my request be sent so that I can access item_id ?

0 likes
3 replies
PersonalHomePage's avatar

@jlrdw let me rephrase the question, what would my request need to be in order for me to be able to access $request->token->item_id?

jlrdw's avatar

@PersonalHomePage

        $data = '{
	"testing": 123,
	"token": {
		"item_id": 456
	}
}';
        $decoded = json_decode($data, true);

        echo $decoded["token"]["item_id"];

Gives 456

Please or to participate in this conversation.