From a72bcffe1a3b1e2b93870dcaad5ed7f06e08d5b8 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 5 Sep 2021 17:23:56 +1000 Subject: [PATCH] Pass through additional arguments to Gate check --- src/functions_laravel.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/functions_laravel.php b/src/functions_laravel.php index 23d4c21..0552e26 100644 --- a/src/functions_laravel.php +++ b/src/functions_laravel.php @@ -66,9 +66,13 @@ function authenticated(): Closure }; } -function can(string $ability): Closure +function can(string $ability, ...$args): Closure { - return function ($arg) use ($ability) { - return Gate::allows($ability, $arg instanceof Model ? $arg : null); + return function ($arg) use ($ability, $args) { + if ($arg instanceof Model) { + array_unshift($args, $arg); + } + + return Gate::allows($ability, $args); }; }