Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Fixes singleton and api singletons creatable|destryoable|only|except combinations #47098

Merged
merged 5 commits into from May 18, 2023

Conversation

nunomaduro
Copy link
Member

This pull request fixes #47088, and the usage of creatable or destroyable Singleton Resources when combined with options such as only or except.

@jessarcher Can you let know what do you think about this, before I deliver it to Taylor? Thanks!

@nunomaduro nunomaduro marked this pull request as draft May 15, 2023 21:25
@nunomaduro nunomaduro changed the title [10.x] Fixes singleton and api singletons when combined with creatable [10.x] Fixes singleton and api singletons creatable|destryoable|only|except combinations May 15, 2023
@jessarcher jessarcher force-pushed the fix/api-resources-only-and-except branch from e08f004 to 5594b54 Compare May 16, 2023 02:28
@jessarcher
Copy link
Member

Hey @nunomaduro

In your implementation, @timacdonald and I noticed an inconsistency between apiSingleton and apiResource. For better or worse, apiResource allows you to use the only method to enable non-API routes, but in your implementation, this was not the case with apiSingleton.

We've rolled back your change to the apiSingleton method in Illuminate\Routing\Router to work the same as apiResource by only setting an initial value for only and deferring everything else to the singleton method. We instead solved #47088 by using the creatable and destroyable options to change the "defaults" that are passed to the getResourceMethods method.

We no longer need any singleton-specific code in the getResourceMethods method, and we no longer need the apiSingleton option at all.

We've made the change as a single commit so you can roll back if you don't agree :)

@@ -427,15 +427,14 @@ public function apiSingletons(array $singletons, array $options = [])
*/
public function apiSingleton($name, $controller, array $options = [])
{
$only = ['show', 'update', 'destroy'];
$only = ['store', 'show', 'update', 'destroy'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jessarcher why was store added here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We previously had some singleton-specific overrides in getResourceMethods that were applied after only, leading to unexpected behavior.

Now, the creatable and destroyable methods just expand the defaults that are passed to getResourceMethods, which can then be reduced by only.

We need to specify store here so that it will be included when using creatable. It's safe to include even when creatable is not called because only can only reduce the defaults, but not expand them.

@nunomaduro nunomaduro marked this pull request as draft May 16, 2023 15:04
Copy link
Member Author

@nunomaduro nunomaduro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for review @taylorotwell.

@nunomaduro nunomaduro marked this pull request as ready for review May 17, 2023 14:16
@taylorotwell taylorotwell merged commit 4b3bd09 into 10.x May 18, 2023
17 checks passed
@taylorotwell taylorotwell deleted the fix/api-resources-only-and-except branch May 18, 2023 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Route::apiSingleton does not respect only() and except()
3 participants