laravel-permission icon indicating copy to clipboard operation
laravel-permission copied to clipboard

Added backed enum as possible role and permission name when finding or creating them

Open EranNL opened this issue 8 months ago • 3 comments

When finding or creating roles and permissions, you can't use an enum like you can when assigning roles or permissions. This PR adds support for backed enums when you find or create them.

Like so:

$permission = Permission::findOrCreate(PermissionEnum::VIEW_USERS);
$role = Role::findOrCreate(RoleEnum::ADMIN);

EranNL avatar Apr 02 '25 12:04 EranNL

Dear contributor,

because this pull request seems to be inactive for quite some time now, I've automatically closed it. If you feel this pull request deserves some attention from my human colleagues feel free to reopen it.

spatie-bot avatar Aug 04 '25 10:08 spatie-bot

Hi. Still considering this for inclusion in next major release. A few things enum-related will be breaking changes, so queuing them for then. Re-opening.

drbyte avatar Aug 04 '25 14:08 drbyte

Note to self, during future review: BackedEnum is not supported before PHP 8.1 ... which is why the PHP 8.0 tests are failing. Hence another reason for queuing for a major release bump.

drbyte avatar Aug 09 '25 01:08 drbyte