Skip to content

Commit

Permalink
[11.x] Add BackedEnum support to Authorize middleware (#52679)
Browse files Browse the repository at this point in the history
* Add backed enum support

* Add test
  • Loading branch information
diaafares authored Sep 6, 2024
1 parent 707bd75 commit 139aba9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Middleware/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Auth\Middleware;

use BackedEnum;
use Closure;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -29,12 +30,14 @@ public function __construct(Gate $gate)
/**
* Specify the ability and models for the middleware.
*
* @param string $ability
* @param \BackedEnum|string $ability
* @param string ...$models
* @return string
*/
public static function using($ability, ...$models)
{
$ability = $ability instanceof BackedEnum ? $ability->value : $ability;

return static::class.':'.implode(',', [$ability, ...$models]);
}

Expand Down

0 comments on commit 139aba9

Please sign in to comment.