php-casbin/laravel-authz

[Question] Please tell me how to expand the list of functions

vvistmn opened this issue · 4 comments

HI!

I called the addFunction method of the FunctionMap class in the controller to create the function. I use RequestMiddleware, the FunctionMap::loadFunctionMap() method is called there - which returns a list of commands by default. And there is no my function. Where can I define my function so that it can be seen from the RequestMiddleware? Or is it necessary to override the default classes?

So far, it turned out to be implemented as follows in composer.json add the following line:

"autoload": { "psr-4": { "App\\": "app/" }, "exclude-from-classmap": ["/vendor/casbin/casbin/src/Model/FunctionMap.php"], "files": ["app/Services/Permissions/FunctionMap.php"] },

@vvistmn hi, can you make a PR to fix it?

@vvistmn
How to add a customized function: https://casbin.org/docs/function#how-to-add-a-customized-function
You can use facade static calls in this project:

Enforcer::addFunction("yourfunction", function(...$args){
     // todo ...
});