Skip to content

Commit

Permalink
feat: register middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Dec 14, 2024
1 parent 23ff45b commit 8fda649
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 8fda649

Please sign in to comment.