From d403dc381570d0173b43cf397fef8f26a625851f Mon Sep 17 00:00:00 2001 From: Matt Wells Date: Wed, 13 May 2015 19:50:05 +0100 Subject: [PATCH] updates resource output to correctly nest attributes Spec: "attributes": an "attributes object", providing information about a resource. See: http://jsonapi.org/format/#document-structure-resource-objects --- src/EchoIt/JsonApi/Model.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/EchoIt/JsonApi/Model.php b/src/EchoIt/JsonApi/Model.php index 42f6513..5c89774 100644 --- a/src/EchoIt/JsonApi/Model.php +++ b/src/EchoIt/JsonApi/Model.php @@ -113,8 +113,14 @@ public function toArray() } //add type parameter - $attributes = $this->attributesToArray(); - $attributes['type'] = $this->getResourceType(); + $model_attributes = $this->attributesToArray(); + unset($model_attributes[$this->primaryKey]); + + $attributes = [ + 'id' => $this->getKey(), + 'type' => $this->getResourceType(), + 'attributes' => $model_attributes + ]; if (! count($relations)) { return $attributes;