user(); if (! $shouldCheckPolicyExistence) { return Gate::forUser($user)->authorize($action, $model); } $policy = Gate::getPolicyFor($model); if ( ($policy === null) || (! method_exists($policy, $action)) ) { /** @var bool | Response | null $response */ $response = invade(Gate::forUser($user))->callBeforeCallbacks( $user, $action, [$model], ); if ($response === false) { throw new AuthorizationException(); } if (! $response instanceof Response) { return Response::allow(); } return $response->authorize(); } return Gate::forUser($user)->authorize($action, $model); } }