Skip to content

Route macro functions: add backed enum support #2823

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

Merged
merged 1 commit into from
Apr 2, 2025

Conversation

Yi-pixel
Copy link
Contributor

It might be simpler to use the following approaches, but they will break the previous tests (because the middleware name returned is the full class name, not the alias)

\Spatie\Permission\Middleware\PermissionMiddleware::using();
\Spatie\Permission\Middleware\RoleMiddleware::using()

@drbyte
Copy link
Collaborator

drbyte commented Mar 23, 2025

I like this.

And your comment about using FQDN::using() is good too. Perhaps we can incorporate both? (Add them, vs changing prior ones)

@Yi-pixel
Copy link
Contributor Author

I like this.

And your comment about using FQDN::using() is good too. Perhaps we can incorporate both? (Add them, vs changing prior ones)

@drbyte Hmm, but with the current approach, allowing a mix of Backed Enum and strings looks pretty good.

Route::permission(['view-post:1', Permission::ReviewPost])

However, if switching to FQDN::using(), there are some issues to be aware of.

As mentioned earlier, FQDN::using() generates the fully qualified class name, whereas the current implementation uses middleware aliases. This means that if the alias in the actual code points to a custom middleware, it could break things (though the likelihood is low).

Alternatively, it might be worth considering modifying FQDN::using() to use middleware aliases instead, ensuring consistent behavior.

@drbyte
Copy link
Collaborator

drbyte commented Apr 2, 2025

Will merge this for now. The other adjustments for using() can be explored separately.

@drbyte drbyte merged commit 71e62a6 into spatie:main Apr 2, 2025
39 checks passed
@drbyte drbyte changed the title Route macro functions add backed enum support Route macro functions: add backed enum support Apr 2, 2025
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.

2 participants