I'm new to Symfony, I come from a MVC framework where there were just one Model class, but here in Symfony we have 2, as far as I've learnt (Entity and Repository)
So, I'm not sure when a method should be put inside the Entity class and when it should be inside the Repository...
for example:
$user->logLogin()
which logs the user login (timestamp, ip, country, user agent ecc.) to a log_logins table, and it's called from a login event listener, where should it go? (I'm not going to create a UserLogins Entity since there is no need to manipulate the data on that table, it's just some read-only information)
$user->getEmail()
. A repository is a way to retrieve entities, so put on repositories any method you need to get them, such asgetUserByEmail
or whatever.log_login
is connected with tableuser
by relation many to one. Tou can use doctrine relations and inuser
entity include methodaddLogLogin()
. Inuser
entity, there will be propertylogLogin
with typeArrayCollection
. It is desctibed in doc