Policies
Apiato policies are just Laravel Policies, and they function in the exact same way as Laravel policies. However, they come with additional rules and conventions specific to Apiato.
To generate new policies, you may use the apiato:make:policy interactive command:
php artisan apiato:make:policy
Rules
- All Policies:
- MUST be placed in the
app/Containers/{section}/{container}/Policiesdirectory. - MUST extend the
App\Ship\Parents\Policies\Policyclass.- The parent extension SHOULD be aliased as
ParentPolicy.
- The parent extension SHOULD be aliased as
- SHOULD be named after the model they are associated with, followed by the
Policysuffix. For instance,UserPolicy.php.
- MUST be placed in the
Folder Structure
app
└── Containers
└── Section
└── Container
└── Policies
├── UserPolicy.php
└── ...
Code Example
Policies are defined exactly as you would define them in Laravel.
Policy Auto-Discovery
Apiato offers a policy auto-discovery feature that eliminates the need for manual registration of model policies. This automatic discovery process relies on adhering to standard Apiato naming conventions for policies.
By following the rules outlined above, you allow Apiato to automatically discover your policies.
To summarize:
- Policies must be stored within the
app/Containers/{section}/{container}/Policiesdirectory. - The policy name should mirror the corresponding model's name while appending a
Policysuffix. For instance, aUsermodel corresponds to aUserPolicypolicy class.