EasyAdmin 4.0 Symfony 5.4 - Validation data when Add, Edit

Viewed 84

I am using EasyAdmin 4.0 and Symfony 5.4. My goal was to set up a Lending Room for Board Games. I have an Entity Reservation and an Entity Rent. I would like to add validation when adding, editing the Entities listed above, consisting in checking whether there is an available copy of the game in the date range provided in the form -> i.e. if there is no reservation, the loan for the given date range is OK, and if it exists, return an error message . How do you advise to do this functionality? Thank you in advance for any help

1 Answers

You can add validation by overwriting persistEntity on your CrudController

public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
{
    if(validation_fail()){
        //Send message
    } else {
        //let him take the natural course
        parent::persistEntity($entityManager,entityInstance);
    }
}
Related