Blocking Methods
Get outta here!
The secure()
Methods
secure()
MethodsNow that you have access to the model, you can use the following method to verify explicit permissions and authorize access. This method will throw an exception if the user does not validate the incoming permissions context (NotAuthorized
).
The
permission
can be an array, string or list of the permissions to validate. The user must have at least one of the permissions specified.The
message
is a custom error message to be used in themessage
string of the exception thrown.
You also have two more authorization methods that will verify certain permission conditions for you:
Conditional Authorizations Using when()
when()
There are also cases where you want to execute a piece of code by determining if the user has access to do so. For example, only a USER_ADMIN
can change people's roles or you want to filter some data for certain users. For this, we have created the when()
method with the following signature:
The
permissions
is a permission array or list that will be Or'edThe
success
is a closure/lambda or UDF that will execute if the permissions validate.The
fail
is a closure/lambda or UDF that will execute if the permissions DID not validate, much like an else statement
Both closures/functions takes in a user
which is the currently authenticated user, the called in permissions
and can return anything.
You can also chain the when()
calls if needed, to create beautiful security contexts. So if we go back to our admin examples, we can do something like this:
We have also added the following whenX()
methods to serve your needs when evaluating the permissions:
Last updated