Skip to content

Support policy responses to allow developers to return custom messages when authorization fails #70

@lindyhopchris

Description

@lindyhopchris

At the moment in our authorizer class we do this:

return $this->gate->check(
    'view',
    $model
);

An improvement would be to support Policy Responses so that the developer can return authorization messages from their policy.

To do that, the code would be something like this:

$response = $this->gate->inspect(
    'view',
    $model
);

if ($response->message()) {
    $response->authorize();
}

return $response->allowed();

I.e. if the authorization response has a message, calling the authorize() method on the response will throw an authorization exception with that message if the authorization has failed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy