From 85c24fb8c194d28ccb105cdcc4df034781b63d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20Portugu=C3=A9s=20Calder=C3=B3?= Date: Thu, 7 Jul 2016 00:00:20 +0200 Subject: [PATCH] missing $model->timestamps value in condition --- .idea/blade.xml | 4 + .idea/composerJson.xml | 9 + .idea/copyright/profiles_settings.xml | 3 + .idea/laravel5-jsonapi.iml | 8 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 705 ++++++++++++++++++ .../JsonApi/Controller/JsonApiController.php | 6 +- .../JsonApi/Controller/JsonApiTrait.php | 9 +- 9 files changed, 755 insertions(+), 3 deletions(-) create mode 100644 .idea/blade.xml create mode 100644 .idea/composerJson.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/laravel5-jsonapi.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/blade.xml b/.idea/blade.xml new file mode 100644 index 0000000..ddb9fb5 --- /dev/null +++ b/.idea/blade.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/composerJson.xml b/.idea/composerJson.xml new file mode 100644 index 0000000..4199499 --- /dev/null +++ b/.idea/composerJson.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/laravel5-jsonapi.iml b/.idea/laravel5-jsonapi.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/laravel5-jsonapi.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ddbd9da --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..5523ee8 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,705 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + + + + + + + + + 1467402359628 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiController.php b/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiController.php index ab13384..713b6d5 100644 --- a/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiController.php +++ b/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiController.php @@ -102,8 +102,10 @@ public function store(Request $request) $model = $this->getDataModel(); $data = (array) $request->get('data'); - $data['attributes'][$model::CREATED_AT] = Carbon::now()->toDateTimeString(); - $data['attributes'][$model::UPDATED_AT] = Carbon::now()->toDateTimeString(); + if (array_key_exists('attributes', $data) && $model->timestamps) { + $data['attributes'][$model::CREATED_AT] = Carbon::now()->toDateTimeString(); + $data['attributes'][$model::UPDATED_AT] = Carbon::now()->toDateTimeString(); + } return $this->addHeaders( $resource->get($data, get_class($this->getDataModel()), $createResource) diff --git a/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php b/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php index 7bfc8b5..2e7e94e 100644 --- a/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php +++ b/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php @@ -10,6 +10,7 @@ namespace NilPortugues\Laravel5\JsonApi\Controller; +use Carbon\Carbon; use Illuminate\Container\Container; use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; @@ -197,10 +198,16 @@ protected function patchAction(Request $request, $id) $resource = new PatchResource($this->serializer); + $model = $this->getDataModel(); + $data = (array) $request->get('data'); + if (array_key_exists('attributes', $data) && $model->timestamps) { + $data['attributes'][$model::UPDATED_AT] = Carbon::now()->toDateTimeString(); + } + return $this->addHeaders( $resource->get( $id, - (array) $request->get('data'), + $data, get_class($this->getDataModel()), $find, $update