I have an api so that inactive users can add 3 products to their store and active users can add unlimited products.
is there a way to add count limitation for a permission?
what I mean:
an inactive user has permission to add products by 3 count limitation.
an active user has permission to add products with no limit.
I think I have to add a new column on permissions table and keep limitation numbers in that. is it a good way?
excuse me for my bad English.
I do not think you need a "permission" package for that.
This permissions package is not built around dynamic rules. (You can combine permission rules with other business logic, but what you described is only dynamic rules, not related to a role/permission like this package provides. At least, that's my interpretation of what you wrote.)
There are several other ways to do it directly in Laravel:
a) controller logic to simply test for "active/inactive", and deny if not allowed
b) Use Laravel's built-in Gate logic, and create a policy for your User.
See https://laravel.com/docs/5.4/authorization
and https://mattstauffer.co/blog/acl-access-control-list-authorization-in-laravel-5-1/
c) perhaps your logic belongs in the store's "basket" object instead of the User object?
thankyou @drbyte
I need this package beacause I have many roles and permission not just active and inactive but its not enough: for example, user have permission(use this package) to add product but just 3 number(limitation).
there is many limitations such as number of products that user can add, number of sub categories and .. so I think is better to save them in database and use laravel Gate logic to authorize. I'm right?
I suppose you can still use this package for part of that. But your enforcement of a certain "number of products" tied to a permission/role will have to be done outside this package.
ie:
if (auth()->user()->can('add 3 products') && $cart->containsItems()->count() <= 3) {
// true
}
Combining the permission name from this package with logic in your application can work. But you have to build the logic to accommodate any enforcing of dynamic numbers.
Most helpful comment
I do not think you need a "permission" package for that.
This permissions package is not built around dynamic rules. (You can combine permission rules with other business logic, but what you described is only dynamic rules, not related to a role/permission like this package provides. At least, that's my interpretation of what you wrote.)
There are several other ways to do it directly in Laravel:
a) controller logic to simply test for "active/inactive", and deny if not allowed
b) Use Laravel's built-in Gate logic, and create a policy for your User.
See https://laravel.com/docs/5.4/authorization
and https://mattstauffer.co/blog/acl-access-control-list-authorization-in-laravel-5-1/
c) perhaps your logic belongs in the store's "basket" object instead of the User object?