It uses symfony/validator to validate your data.
on HTML request
src/Entity/Book.php
namespaceApp\Entity;
use App\Form\Type\BookType;
use Sylius\Resource\Model\ResourceInterface;
use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\Create;
use Symfony\Component\Validator\Constraintsas Assert;
#[AsResource(
formType:BookType::class,
operations:[
newCreate(),
],
)
class Book implements ResourceInterface
{
// ...
#[Assert\NotBlank()]
private?string$title;
}In this example, validation will fail when adding a new book without specifying its title on the form.
on API request
In this example, validation will fail when adding a new book without specifying its title on the payload.
Disable validation
In some case, you may want to disable this validation.
For example, in a "publish" operation, you may want to apply a state machine transition without validation existing data.
Last updated
Was this helpful?
