sajad torkamani
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
  
// All the usual annotations on user....
class User {
  #[Groups(['user:read:item'])]
  #[SerializedName('hasCreatedArticle')]
  public function hasCreatedArticle(): bool
  {
    return $this->getArticles()->count() > 0;
  }

Now, you’ll get a hasCreatedArticle field name instead of the default createdArticle.

Leave a comment

Your email address will not be published. Required fields are marked *