Search code examples
phpsymfonydoctrineentity

users & roles both are different entites in symfony 2.8


I'm working on one project for that i need solution for users & roles both are different entities.

user entity

user
id
fname
lname
email

role entity

roles
id
roles

user_roles entity

id
user_id
role_id

Solution

  • You need to create Role class which implements RoleInterface, and add it to your User class with ManyToMany relationship, and return the array of roles in your getRoles() method, that's it.