Multiple policy
kingleuther opened this issue · 3 comments
How to use multitple policy in one model? is that possible? thanks!
@kingleuther no this is not posible, and I do not think that it will be.
The main idea of a policy class is - to controll what a "Authorized" model (like User
model) can do with a "subject" model (like Post
model)
So in the end we will have every time 1 policy for one to one model controlls.
const User = use('App/Models/User')
const Post = use('App/Models/Post')
const user = await User.find(1)
const post = await Post.find(1)
console.log(
user.can('add', Post),
user.can('edit', post)
)
As you can see, in all cases we are sending the model into the can
method. This will give use info where to take the policy class.
Please describe a situation where 2 policies are needed by your opinion :)
I was just thinking that I may need multiple policy. If ever I came through a use-case that needs multiple policy I will let you know.
For the meantime, can you give example how to use the canNot().
@kingleuther the canNot()
is only the opposite of can()
and should be included when you will "mix" the Trait with User model