Skip to content

Commit

Permalink
Put was missing UPDATED_AT fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Jul 6, 2016
1 parent 6515856 commit b4508c7
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php
Expand Up @@ -145,24 +145,23 @@ protected function createResourceCallable()

/**
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
* @param $id
* @return Response
*/
protected function putAction(Request $request, $id)
{
$find = $this->findResourceCallable($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)
);
}

Expand All @@ -187,8 +186,7 @@ protected function updateResourceCallable()

/**
* @param Request $request
* @param $id
*
* @param $id
* @return Response
*/
protected function patchAction(Request $request, $id)
Expand All @@ -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)
);
}

Expand Down

0 comments on commit b4508c7

Please sign in to comment.