From 8fda64937454fefacc2f67beb3d61e1134247553 Mon Sep 17 00:00:00 2001 From: mychidarko Date: Sat, 14 Dec 2024 17:43:56 +0000 Subject: [PATCH] feat: register middleware --- src/Auth.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Auth.php b/src/Auth.php index a146a39..0e3b406 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -608,6 +608,38 @@ public function middleware(string $middleware, callable $callback) }); } + if ($middleware === 'is') { + return app()->registerMiddleware('is', function ($role) use ($callback) { + if ($this->user()?->isNot($role)) { + $callback(); + } + }); + } + + if ($middleware === 'isNot') { + return app()->registerMiddleware('isNot', function ($role) use ($callback) { + if ($this->user()?->is($role)) { + $callback(); + } + }); + } + + if ($middleware === 'can') { + return app()->registerMiddleware('can', function ($role) use ($callback) { + if ($this->user()?->can($role)) { + $callback(); + } + }); + } + + if ($middleware === 'cannot') { + return app()->registerMiddleware('cannot', function ($role) use ($callback) { + if ($this->user()?->cannot($role)) { + $callback(); + } + }); + } + app()->registerMiddleware($middleware, $callback); }