-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[v6] Add BackedEnum support #2391
Conversation
Feedback welcome. I know there are lots of varying ways people like to implement enums. This covers the basics, but if there are some clear use-cases that aren't supported here, this is a good time to make adjustments. |
/cc @boumanb |
4d7b9ee
to
fcdd577
Compare
Great job, this should really be the recommended way to implement permissions. I did it so far by overriding methods in the HasRole and HasPermission traits, not having to do this would be great. Having all permissions defined in an Enum is so much cleaner and sustainable rather than using plain strings. Really neat with helpers as in your example to tie presentational data with each permission which I've been using as well to tie a description and category to each permission |
Why is the interface needed? |
@drbyte to me this looks like a perfect PR example. It's specific and well-documented.
If I may answer; to assure it's a
The approach of @drbyte follows the example of the comment in the BackedEnum PHP documentation. Although the Nevertheless, I think the solution works without extending the |
Sure but you can do this to get a BackedEnum: ...and that interface is never checked anywhere, only Sorry for my confusion if I'm way off track here, trying to learn! |
I've edited my comment. I think you're right and the |
Yes, you're correct. I had tried extending BackedEnum, but that triggered errors. I didn't test Enum directly without extending or implementing an interface. I'll update the code in a bit. |
Updated. Question: For those of you who have been using Enums already, how have you handled |
BackedEnum tidying
I think it was missing to add support for enum in the models |
@erikn69 I'd support a PR for that addition. |
Fixes #1991
Note: Requires PHP 8.1+
/cc @ceejayoz
/cc @edalzell