Skip to content

Commit

Permalink
missing $model->timestamps value in condition
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Jul 6, 2016
1 parent 1b24b2e commit 85c24fb
Show file tree
Hide file tree
Showing 9 changed files with 755 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .idea/blade.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/composerJson.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/laravel5-jsonapi.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

705 changes: 705 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 85c24fb

Please sign in to comment.