I have a permissions table, which will eventually have up to 100 permissions. Things like "Add User", "Edit User", etc. Would it be acceptable to create a const
for each permission in my Permissions
model?
The reason is that I'll have a single method that will be used to check if a user has a permission, so I'd want to be able to do something like $this->hasPermission(Permission::USER_ADD)
and not have to use magic numbers that would require me to it up every time.
I initially was aiming to trim down the number of records, so instead of having individual CRUD permissions for each resource, I'd just have a permissions for Users along with a corresponding column for the CRUD actions. However, it's not flexible enough for me since there are cases where a particular permission doesn't fall under those CRUD actions. For instance, "View Disabled Users".
I don't particularly see a problem with the constants, but wanted some input if this is a bad practice or the like. Thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire