Monday, 15 February 2010

php - Laravel and JSON response -



php - Laravel and JSON response -

i have json response looks this:

{ "success": true, "ownerslist": [ { "propertieslist": [], "email": "email@email.com" }, { "propertieslist": [], "email": "email2@email.com" } ] }

how grab of propertieslist associated specific "email" value?

i don't think need fancy laravel this. want utilize guzzle (which laravel dependency) since it's nice , easy curl wrapper php.

// assumes api response in variable $api_response_body_as_a_string $o_api_response = json_decode($api_response_body_as_a_string); $owners_list = $o_api_response->owners_list; $propertieslist = null; foreach($owners_list $this_owner) { if('email@to.find' === $this_owner->email) { $propertieslist = $this_owner->$propertieslist; break; } } // $propertieslist has result or null

original question (before op clarification):

you don't have code related laravel in question, i'll venture guess querying table propertieslist foreign key of ownerslist model: http://laravel.com/docs/eloquent#eager-loading

otherwise, more info setup (models , relationships) necessary help you.

php json laravel

No comments:

Post a Comment