We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Form, unique with additional check

I have a form for making projects and the name should be unique, but it should only match unique names with other active projects (so theres no two active projects with the same name). But it does not matter if the name is equal to inactive projects names. It's a weird request but I'm looking how to implement this.

Does anyone know a good way of implementing this via form objects or model?

Currently the validation for the field in the model looks like this.

public function validation()
{
        $validator = new Validation();

        $validator->add(
            "name",
            new Uniqueness(
                [
                    "message" => "The name must be unique",
                ]
            )
        );

        return $this->validate($validator);
}


32.3k
Accepted
answer

With incubator > validator > uniqueness you can use a exclude param, but is very simple

You can use it like example to your request

Good luck



13.8k