Checking
Learn how to check permissions in your application
Overview
Permix provides two methods for checking permissions: check
and checkAsync
. Both methods return a boolean indicating whether the action is allowed.
check
The check
method allows you to verify if certain actions are permitted. It returns a boolean indicating whether the action is allowed:
Array
You can check multiple actions at once by passing an array of actions. All actions must be permitted for the check to return true:
All
Use the special 'all' keyword to verify if all possible actions for an entity are permitted:
checkAsync
When you need to ensure permissions are ready before checking, use checkAsync
. This is useful when permissions might be set up asynchronously:
In most cases you should use check
instead of checkAsync
. checkAsync
is useful when you need to ensure permissions are ready before checking, for example in route middleware.
Data-Based
You can define permissions that depend on the data being accessed:
You still can check permissions without providing the data, but it will return false
in this case.
Type Safety
Permix provides full type safety for your permissions: