How would you refactor the following permission checking to a better one?
Currently the way users are checked if they have permission to access some resource is done using Middlewares:
There is a DB table with list of available permissions
Then there is another DB table that matches users and their corresponding permission.(users can have many permissions)
For each permission there is a Middleware file, that all it does is to match the authenticated user's list of permissions against the specific permission file check. So for example Permission_X_Middleware.php will check if the current user has permission X in the list of his permissions.
Every Middleware file created is registered in the Kernel.php
For the roue that needs permission, the Middleware is attached: