Could some explain to me the difference between : @Security("has_role("ROLE_ADMIN")")
and @Security("is_granted("ROLE_ADMIN")")
and which one is more recommended?
They do the same job in that case, but the has_role()
function in security expressions is deprecated since Symfony 4.2, so we should use is_granted()
instead.
I think that has_role() checks if the user already has the role. On the other hand, is_granted() runs the Voters to check if there is a role to be added to the existing roles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With