From 3177c905d916be92856b1525525cccc1e1df0aac Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 10 Mar 2021 12:36:15 +0100 Subject: [PATCH] wip --- readme.md | 2 +- src/Traits/InteractsWithNovaResources.php | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/readme.md b/readme.md index 76ff724..192acae 100644 --- a/readme.md +++ b/readme.md @@ -16,7 +16,7 @@ First thing you will need to do after creating a resource tests is filling the ` the resource properties. It's also not needed to map each property of the resource, just the ones that change or are required to be diferent. ```php -protected function remapResource($resource) +protected function remapResource($resource): array { return [ 'location' => $resource->location_id, diff --git a/src/Traits/InteractsWithNovaResources.php b/src/Traits/InteractsWithNovaResources.php index 68679bd..74e2aef 100644 --- a/src/Traits/InteractsWithNovaResources.php +++ b/src/Traits/InteractsWithNovaResources.php @@ -82,7 +82,7 @@ protected function storeResource($data = []): TestResponse $resource = $this->mergeData($data, true); return $this->beDefaultUser() - ->novaStore($this->resourceClass::uriKey(), $resource->toArray()); + ->novaStore($this->resourceClass::uriKey(), $resource); } /** @@ -97,10 +97,7 @@ protected function updateResource($data = []): TestResponse $resource = $this->mergeData($data); return $this->beDefaultUser() - ->novaUpdate( - $this->resourceClass::uriKey() . '/' . $resource['id'], - $resource->toArray() - ); + ->novaUpdate($this->resourceClass::uriKey() . '/' . $resource['id'], $resource); } /** @@ -116,7 +113,7 @@ protected function deleteResource($data = []): TestResponse $data = ['id' => $data]; } - $resource = Arr::only($this->mergeData($data)->toArray(), 'id'); + $resource = Arr::only($this->mergeData($data), 'id'); return $this->beDefaultUser() ->novaDelete($this->resourceClass::uriKey(), $resource); @@ -203,7 +200,7 @@ private function mapIndexToName($list): array * * @return \Illuminate\Database\Eloquent\Model */ - private function mergeData($data = [], $isStoreRequest = false): Model + private function mergeData($data = [], $isStoreRequest = false): array { if (!is_array($data) && $data instanceof Model) { $data = $data->toArray(); @@ -214,10 +211,10 @@ private function mergeData($data = [], $isStoreRequest = false): Model ? $factory->make($data) : $factory->create($data); - return $resource - ->makeVisible($resource->getHidden()) - ->forceFill($this->remapResource($resource)) + $resource->makeVisible($resource->getHidden()) ->forceFill($this->clearPrefilledData()); + + return array_merge($resource->toArray(), $this->remapResource($resource)); } /**