Symfony DivisibleBy Constraint

Introduction

Introduced in [Symfony 4.2](Symfony 4.2), DivisibleBy enforces specific increments on a number.

Syntax

// src/Entity/Item.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;

class Item
{
/**
* @Assert\DivisibleBy(0.25)
*/
protected $weight;

/**
 * @Assert\DivisibleBy(
 *     value = 5,
 *     message = "This item requires to be stocked in multiples of 5 units."
 * )
 */
protected $quantity;

}