*/ class MatriculeCast implements CastsAttributes { /** @param array $attributes */ public function get(Model $model, string $key, mixed $value, array $attributes): Matricule { if ($value === null || ! is_string($value)) { throw new \UnexpectedValueException('Matricule must be a string.'); } return new Matricule($value); } /** @param array $attributes */ public function set(Model $model, string $key, mixed $value, array $attributes): string { if (! $value instanceof Matricule) { throw new \UnexpectedValueException('The given value is not an instance of Matricule.'); } return $value->value; } }