Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Commit 9f8c66d

Browse files
Added transfer key detection in validateModel helper function
1 parent 01aec71 commit 9f8c66d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/helpers.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,21 @@ function validateModel(object|string $model, array $data): array
4747
$model = new $model();
4848
}
4949

50-
$properties = (new ReflectionClass($model))->getProperties();
50+
$reflection = (new ReflectionClass($model));
51+
$properties = $reflection->getProperties();
5152

5253
$errors = [];
54+
$transferKey = (count($reflection->getAttributes(SnakeToCamelCase::class, ReflectionAttribute::IS_INSTANCEOF)) > 0);
5355

5456
foreach ($properties as $property) {
5557
$validators = $property->getAttributes(Validator::class, ReflectionAttribute::IS_INSTANCEOF);
5658

5759
foreach ($validators as $validator) {
5860
$validator = $validator->newInstance();
5961
/** @var Validator $validator */
60-
$key = camelCaseToSlugFormat($property->getName());
62+
$key = $transferKey ?
63+
camelCaseToSlugFormat($property->getName()) :
64+
$property->getName();
6165
$value = is_object($model) && isset($model->{$property->getName()}) ? $model->{$property->getName()} : $data[$key] ?? null;
6266

6367
try {

0 commit comments

Comments
 (0)