I have the
Class User {
@OneToMany
private $profiles
}
Now I have the $user entity in my controller but I also want the first or last profile based on date. How can I achieve this?
I have the method getProfiles()
but I think that will return the array collection.
$user->getProfiles()->first()
will do it, as long as you are declaring the $profiles
property as a
\Doctrine\Common\Collections\ArrayCollection
in the constructor of your class.
You can easily get the first one like that :
$first = $this->get('doctrine.manager')->getRepository(MyEntity::class)->findOneBy([]);
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