Skip to content

Commit

Permalink
Merge pull request #14726 from emargareten/3.x
Browse files Browse the repository at this point in the history
Add backed enum for $abilities type
  • Loading branch information
danharrin authored Nov 7, 2024
2 parents 3e0c799 + 87a489e commit 62bd101
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/actions/src/Concerns/CanBeHidden.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Filament\Actions\Concerns;

use BackedEnum;
use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
Expand All @@ -20,6 +21,10 @@ trait CanBeHidden
*/
public function authorize(mixed $abilities, Model | string | array | null $arguments = null): static
{
if ($abilities instanceof BackedEnum) {
$abilities = $abilities->value;
}

if (is_string($abilities) || is_array($abilities)) {
$this->authorization = [
'type' => 'all',
Expand All @@ -34,11 +39,15 @@ public function authorize(mixed $abilities, Model | string | array | null $argum
}

/**
* @param string | array<string> $abilities
* @param string | BackedEnum | array<string> $abilities
* @param Model | array<mixed> | null $arguments
*/
public function authorizeAny(string | array $abilities, Model | array | null $arguments = null): static
public function authorizeAny(string | BackedEnum | array $abilities, Model | array | null $arguments = null): static
{
if ($abilities instanceof BackedEnum) {
$abilities = $abilities->value;
}

$this->authorization = [
'type' => 'any',
'abilities' => Arr::wrap($abilities),
Expand Down

0 comments on commit 62bd101

Please sign in to comment.