Search code examples
phplaravellaravel-authorization

Possible to register a Laravel policy without a model?


I'm working on a Laravel project that leverages policies for authorization, and this works well when I'm authorizing an entity that has a corresponding model. However, not every entity I want to authorize has a corresponding model.

Is there a way to register a policy without a model (or is that fundamentally incorrect?), or should I take a different approach?


Solution

  • You can with Gates, not with Policies.

    • Policies are classes that organize authorization logic around a particular model or resource.
    • Gates are useful to manage authorizations for business logic that don't involve a particular model or resource.

    Here is Laravel documentation about Gates: