Skip to content

Commit

Permalink
[Docs] Update to note Laravel 11.23 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
drbyte committed Sep 19, 2024
1 parent a6cfb37 commit 05f620c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/basic-usage/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum RolesEnum: string

## Creating Roles/Permissions using Enums

When creating roles/permissions, you cannot pass a Enum name directly, because Eloquent expects a string for the name.
When **creating** roles/permissions, you cannot pass an Enum name directly, because Eloquent expects a string for the name.

You must manually convert the name to its value in order to pass the correct string to Eloquent for the role/permission name.

Expand All @@ -62,15 +62,15 @@ Same with creating Permissions.

In your application code, when checking for authorization using features of this package, you can use `MyEnum::NAME` directly in most cases, without passing `->value` to convert to a string.

There will be times where you will need to manually fallback to adding `->value` (eg: `MyEnum::NAME->value`) when using features that aren't aware of Enum support. This will occur when you need to pass `string` values instead of an `Enum`, such as when interacting with Laravel's Gate via the `can()` methods/helpers (eg: `can`, `canAny`, etc).
There may occasionally be times where you will need to manually fallback to adding `->value` (eg: `MyEnum::NAME->value`) when using features that aren't aware of Enum support, such as when you need to pass `string` values instead of an `Enum` to a function that doesn't recognize Enums (Prior to Laravel v11.23.0 the framework didn't support Enums when interacting with Gate via the `can()` methods/helpers (eg: `can`, `canAny`, etc)).

Examples:
```php
// the following are identical because `hasPermissionTo` is aware of `BackedEnum` support:
$user->hasPermissionTo(PermissionsEnum::VIEWPOSTS);
$user->hasPermissionTo(PermissionsEnum::VIEWPOSTS->value);

// when calling Gate features, such as Model Policies, etc
// when calling Gate features, such as Model Policies, etc, prior to Laravel v11.23.0
$user->can(PermissionsEnum::VIEWPOSTS->value);
$model->can(PermissionsEnum::VIEWPOSTS->value);

Expand Down

0 comments on commit 05f620c

Please sign in to comment.