-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Enum as $cast on Permission model #2805
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
Comments
We should probably start by expanding the test suite to account for using I think "fixing" it will also require an update to the contract signatures, to allow for |
In the meantime you can still use enums without using Docs have been updated to add this workaround. |
You are indeed correct. It would be beneficial to include a fix for this bug in the next update, if feasible. |
Notes to self: Ref #2609
|
Description
According to the official documentation, Laravel Permission package should support PHP Enums when used as permission names. However, when using a BackedEnum for name, the package fails with the following error:
There is no permission named
..
for guard..
.Despite the permission existing in the database, the package does not recognize it when using an Enum cast.
Version: 6.x (latest)
Environment:
PHP: 8.2+
Laravel: 10.x
Database: MySQL 8.0+
OS: macOS
Steps To Reproduce
'permission' => \App\Containers\CustomPermission::class,
4. Assign permission to existing role
Expected Behavior
The package should correctly retrieve the permission from the database.
givePermissionTo() should accept an Enum.
Actual Behavior
The package throws an exception stating that the permission does not exist.
The problem is in PermissionRegistrar file.
Example Application
No response
Version of spatie/laravel-permission package:
6.13
Version of laravel/framework package:
10.x
PHP version:
8.2
Database engine and version:
No response
OS: Windows/Mac/Linux version:
No response
The text was updated successfully, but these errors were encountered: