From 0512820180e03e41eafc819e0ffe6ff51bb8b8b8 Mon Sep 17 00:00:00 2001 From: Bartek Maciejewski Date: Wed, 26 Jul 2017 13:52:09 +0200 Subject: [PATCH 1/2] Update Parameters.php fixed for primary key other than 'id' nad $parent.'_id' --- src/Efficiently/AuthorityController/Parameters.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Efficiently/AuthorityController/Parameters.php b/src/Efficiently/AuthorityController/Parameters.php index 2d52f5e..e8b4aab 100644 --- a/src/Efficiently/AuthorityController/Parameters.php +++ b/src/Efficiently/AuthorityController/Parameters.php @@ -46,12 +46,13 @@ public function fillController($controller) if ($lastRouteParamKey === 'id' || $resourceId === str_singular($lastRouteParamKey)) { $id = last($routeParams); if (is_a($id, 'Illuminate\Database\Eloquent\Model')) { - $id = $id->getKey(); - } - if (is_string($id) || is_numeric($id)) { - array_pop($routeParams); - $routeParamsParsed['id'] = $id; - } + $object = $id; + $id = $id->getKey(); + } + if (is_string($id) || is_numeric($id)) { + array_pop($routeParams); + $routeParamsParsed[$object->getKeyName()] = $id; + } } foreach ($routeParams as $parentIdKey => $parentIdValue) { From 81b5a76638320f59942b478965beefbf9b2a4d96 Mon Sep 17 00:00:00 2001 From: BartekMaciejewski Date: Wed, 30 Aug 2017 21:51:35 +0200 Subject: [PATCH 2/2] test commit --- .gitignore | 2 + .idea/workspace.xml | 317 ++++++++++++++++++ .../AuthorityController/Parameters.php | 14 +- tests/AcParametersTest.php | 2 + 4 files changed, 328 insertions(+), 7 deletions(-) create mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index fce6c79..2a9b83a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /vendor composer.phar .DS_Store +.idea/ +.idea/workspace.xml \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..32054c7 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,317 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + true + + + + DIRECTORY + + false + + + + + + + + + 1504120043462 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Efficiently/AuthorityController/Parameters.php b/src/Efficiently/AuthorityController/Parameters.php index e8b4aab..09235d4 100644 --- a/src/Efficiently/AuthorityController/Parameters.php +++ b/src/Efficiently/AuthorityController/Parameters.php @@ -46,13 +46,13 @@ public function fillController($controller) if ($lastRouteParamKey === 'id' || $resourceId === str_singular($lastRouteParamKey)) { $id = last($routeParams); if (is_a($id, 'Illuminate\Database\Eloquent\Model')) { - $object = $id; - $id = $id->getKey(); - } - if (is_string($id) || is_numeric($id)) { - array_pop($routeParams); - $routeParamsParsed[$object->getKeyName()] = $id; - } + $object = $id; + $id = $id->getKey(); + } + if (is_string($id) || is_numeric($id)) { + array_pop($routeParams); + $routeParamsParsed[$object->getKeyName()] = $id; + } } foreach ($routeParams as $parentIdKey => $parentIdValue) { diff --git a/tests/AcParametersTest.php b/tests/AcParametersTest.php index fce3f6b..c037851 100644 --- a/tests/AcParametersTest.php +++ b/tests/AcParametersTest.php @@ -159,6 +159,8 @@ public function testResolveResourceIdFromRequest() $this->call('GET', '/projects/5');// show action + dd($this->parameters, $this->call('GET', '/projects/5')); + $this->assertArrayHasKey('id', $this->getProperty($parameters, 'params')); $this->assertEquals($this->getProperty($parameters, 'params')['id'], '5');