Date custom constraint validation

  constraints, php, symfony, symfony4, validation

I wrote custom constraint for my entity where I have startDate and endDate where I want to avoid overlapping when saving new ones.


namespace AppEntity;

use DoctrineORMMapping as ORM;
use AppValidatorConstraintsNotOverlapping;

class Product
     * @ORMId()
     * @ORMGeneratedValue()
     * @ORMColumn(type="integer")
    private $id;

     * @ORMColumn(type="date", nullable=false)
    private $startDate;

     * @ORMColumn(type="date", nullable=true)
    private $endDate;

Then I completly use this gist : full example ; Which I think is the best solution for me.

But as I am new at writing custom constraint validations can someone clarify how I can now use it? Is there something I should include in an entity or directly in service method where I am persisting entity?

What am I missing here?

Source: Symfony Questions