Skip to main content

Overview

Policies are Laravel classes that define authorization logic for models. Unleash Commerce Core includes built-in policies for models like Order, Customer, and more. You can replace these policies with custom implementations to control who can perform actions on your models.

Extending a Core Policy

If you only need to tweak behavior, extend the default core policy and override the specific methods you want to change:

Policy Return Values

Policies should return one of three values:
  • true - The action is authorized
  • false - The action is explicitly denied (even for super admins)
  • null - Let the default authorization gate handle the decision

Replacing a Core Policy

Register your custom policy in a service provider:

Using Policies in Your Code

Check authorization in controllers:
Check authorization in views:

Testing Policies

Test your custom policies to ensure authorization works correctly:

Available Core Policies

Refer to the Policies Reference for a complete list of available policies you can replace.