Validation
It uses symfony/validator to validate your data.
on HTML request
namespace App\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\Constraints as Assert;
#[AsResource(
formType: BookType::class,
operations: [
new Create(),
],
)
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