Support the ongoing development of Laravel.io →
posted 8 years ago
Requests
Last updated 1 year ago.
0

Hi

If you can show us the nested object it would help, just copy and paste using 3 tilde signs before and after the entry so that the it looks more readable. I will take what you had above and put it between tilde (the key next to number 1) so that you can see what it looks like:

{ "name": "test", "description": "test", "startdate": "2016-02-21T13:00:00.000Z", "enddate": "2016-02-23T13:00:00.000Z", "coach": 
{ "uuid": "76fdd664-d830-11e5-9d46-00ffc9587cbc" }, "category": 
{ "uuid": "771e6de4-d830-11e5-9d46-00ffc9587cbc" }, "useruuid": "76d65a2d-d830-11e5-9d46-00ffc9587cbc", "routines": 
["775b2726-d830-11e5-9d46-00ffc9587cbc"] }
Last updated 8 years ago.
0

on your controller

$request->json();

will get you the json request as an array

$request->json()->name
0

Hi @astroanu ... I know how to get the value from the parent object as you said.

$data = $request->json->all();

$name = $data->name; // this one is ok

$coach_uuid = $data->coach->uuid; // this nested one didn't work !!!

$category_uuid = $data->category->uuid; // this nested one didn't work !!!

Last updated 8 years ago.
0

AtomicRSA said:

Hi

If you can show us the nested object it would help, just copy and paste using 3 tilde signs before and after the entry so that the it looks more readable. I will take what you had above and put it between tilde (the key next to number 1) so that you can see what it looks like:

{ "name": "test", "description": "test", "startdate": "2016-02-21T13:00:00.000Z", "enddate": "2016-02-23T13:00:00.000Z", "coach": 
{ "uuid": "76fdd664-d830-11e5-9d46-00ffc9587cbc" }, "category": 
{ "uuid": "771e6de4-d830-11e5-9d46-00ffc9587cbc" }, "useruuid": "76d65a2d-d830-11e5-9d46-00ffc9587cbc", "routines": 
["775b2726-d830-11e5-9d46-00ffc9587cbc"] }

If you look at the JSON above, the coach, the category and routines are nested object.

0

I found away to do this nested JSON object thingy but not elegant :)

$data = $request->json()->all();

// Log::debug($request);

// $phpArray = json_decode($data,true);

$name = $data['name'];

$coach_uuid = $data['coach']['uuid']; // works now !!!

$category_uuid = $data['category']['uuid']; // works now!!!

There gotta a better way to handle this

0

Well i displayed nested objects in a view like this and i think it should work for you:

$data->name
$data->coach->uuid
$data->coach->category->uuid
0

dcalliances said:

I found away to do this nested JSON object thingy but not elegant :)

$data = $request->json()->all();

// Log::debug($request);

// $phpArray = json_decode($data,true);

$name = $data['name'];

$coach_uuid = $data['coach']['uuid']; // works now !!!

$category_uuid = $data['category']['uuid']; // works now!!!

There gotta a better way to handle this

0

It doesn't work for me

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.