diff --git a/src/Http/Controllers/Features/AuthorizesUserActionsOnModelsTrait.php b/src/Http/Controllers/Features/AuthorizesUserActionsOnModelsTrait.php index 5a19116..8eace4b 100644 --- a/src/Http/Controllers/Features/AuthorizesUserActionsOnModelsTrait.php +++ b/src/Http/Controllers/Features/AuthorizesUserActionsOnModelsTrait.php @@ -4,6 +4,7 @@ use Illuminate\Contracts\Auth\Access\Gate; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; /** * Trait AuthorizesUsersActionsAgainstModelsTrait @@ -100,6 +101,13 @@ public function userCan($ability, $arguments = []) return true; } + // If not, check if we have a custom Response object, and if so, utilise it + // @var $response \Illuminate\Auth\Access\Response + $response = app(Gate::class)->forUser($user)->inspect($ability, $arguments); + if (! empty($response->message())) { + throw new HttpException($response->code(), $response->message()); + } + return false; } diff --git a/src/Http/Controllers/Features/JWTAuthenticationTrait.php b/src/Http/Controllers/Features/JWTAuthenticationTrait.php index 7991bf4..bd90af2 100644 --- a/src/Http/Controllers/Features/JWTAuthenticationTrait.php +++ b/src/Http/Controllers/Features/JWTAuthenticationTrait.php @@ -76,7 +76,7 @@ public function getUser() */ protected function respondWithToken($token) { - $tokenReponse = new \Stdclass; + $tokenReponse = new \stdClass; $tokenReponse->jwt = $token; $tokenReponse->token_type = 'bearer';