From b4508c7e7fd861891782cf695495b8a33513f85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20Portugu=C3=A9s=20Calder=C3=B3?= Date: Thu, 7 Jul 2016 00:31:56 +0200 Subject: [PATCH] Put was missing UPDATED_AT fix --- .../JsonApi/Controller/JsonApiTrait.php | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php b/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php index 2e7e94e..ec08fca 100644 --- a/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php +++ b/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php @@ -145,8 +145,8 @@ protected function createResourceCallable() /** * @param Request $request - * - * @return \Symfony\Component\HttpFoundation\Response + * @param $id + * @return Response */ protected function putAction(Request $request, $id) { @@ -154,15 +154,14 @@ protected function putAction(Request $request, $id) $update = $this->updateResourceCallable(); $resource = new PutResource($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'), - get_class($this->getDataModel()), - $find, - $update - ) + $resource->get($id, $data, get_class($model), $find, $update) ); } @@ -187,8 +186,7 @@ protected function updateResourceCallable() /** * @param Request $request - * @param $id - * + * @param $id * @return Response */ protected function patchAction(Request $request, $id) @@ -205,13 +203,7 @@ protected function patchAction(Request $request, $id) } return $this->addHeaders( - $resource->get( - $id, - $data, - get_class($this->getDataModel()), - $find, - $update - ) + $resource->get($id, $data, get_class($model), $find, $update) ); }