Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c997566
feat: add message method to validation rules for custom error messages
barbosa89 Oct 6, 2025
c6302a2
feat: update failing rules to store error messages instead of rule cl…
barbosa89 Oct 6, 2025
8c5d0d4
test(refactor): update validation tests to use error message keys ins…
barbosa89 Oct 6, 2025
f92652d
style: php cs
barbosa89 Oct 6, 2025
a07f557
feat: add message method to validation rules for float, integer, and …
barbosa89 Oct 6, 2025
c250c97
feat: add validation messages for various rules in English language file
barbosa89 Oct 6, 2025
9810c3b
feat: add unit tests for Required validation rule
barbosa89 Oct 6, 2025
5084445
test: add additional tests for Max validation rule messages
barbosa89 Oct 6, 2025
2ffe367
test: add comprehensive validation rule messages tests
barbosa89 Oct 6, 2025
760cec6
test: add unit test for Confirmed validation rule
barbosa89 Oct 6, 2025
e72efb8
test: add unit tests for DoesNotEndWith and DoesNotStartWith validati…
barbosa89 Oct 6, 2025
cc8beaf
test: add unit tests for EndsWith and StartsWith validation rules
barbosa89 Oct 6, 2025
7b2f698
test: add unit tests for Format and IsDate validation rules
barbosa89 Oct 6, 2025
650d712
test: add unit tests for In and NotIn validation rules
barbosa89 Oct 6, 2025
ee52cc5
test: add unit tests for RegEx validation rule
barbosa89 Oct 6, 2025
b881fb9
test: add unit tests for UUID and ULID validation rules
barbosa89 Oct 6, 2025
71a8357
refactor: remove unused message method from Rule class
barbosa89 Oct 6, 2025
9b5c40d
feat: add message method to Digits and DigitsBetween validation rules
barbosa89 Oct 6, 2025
d146042
feat: add dictionary validation message to language file
barbosa89 Oct 6, 2025
b0fd99d
fix: update validation error messages for clarity in ValidatorTest
barbosa89 Oct 6, 2025
7bf16c6
test: add unit tests for various validation rules including Between, …
barbosa89 Oct 6, 2025
b57183e
refactor: remove RuleMessagesTest file to streamline validation tests
barbosa89 Oct 6, 2025
fefca51
test: add unit tests for date validation rules including After, After…
barbosa89 Oct 6, 2025
89818ae
style: php cs
barbosa89 Oct 6, 2025
2da29e3
test: add unit tests for Digits and DigitsBetween validation rules
barbosa89 Oct 6, 2025
487afc1
test: add unit tests for IsCollection and IsList validation rules
barbosa89 Oct 6, 2025
8713d19
test: add unit tests for Min rule message generation
barbosa89 Oct 6, 2025
92f54d3
test: add unit tests for Exists and Unique validation rules
barbosa89 Oct 6, 2025
489bfd7
test: add unit tests for Mimes validation rule
barbosa89 Oct 6, 2025
a4d185d
feat(validation): add missing translation keys and update tests to as…
barbosa89 Oct 7, 2025
6f4d426
refactor(validation): use getFieldForHumans() across rule error messages
barbosa89 Oct 7, 2025
8904b16
style: php cs
barbosa89 Oct 7, 2025
a713a37
refactor(validation): update field label for last name in validation …
barbosa89 Oct 7, 2025
706a855
tests: display field name for human when field is registered in field…
barbosa89 Oct 7, 2025
b7a5f97
chore: rename tests, remove comment [skip ci]
barbosa89 Oct 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Validation/Contracts/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public function setField(string $field): self;
public function setData(Dot|array $data): self;

public function passes(): bool;

public function message(): string|null;
}
19 changes: 19 additions & 0 deletions src/Validation/Rules/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,23 @@ public function passes(): bool

return $value >= $this->min && $value <= $this->max;
}

public function message(): string|null
{
$value = $this->data->get($this->field) ?? null;
$type = gettype($value);

$key = match ($type) {
'string' => 'validation.between.string',
'array' => 'validation.between.array',
'object' => 'validation.between.file',
default => 'validation.between.numeric',
};

return trans($key, [
'field' => $this->getFieldForHumans(),
'min' => $this->min,
'max' => $this->max,
]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/Confirmed.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ public function passes(): bool
&& $confirmation !== null
&& $original === $confirmation;
}

public function message(): string|null
{
return trans('validation.confirmed', [
'field' => $this->getFieldForHumans(),
'other' => $this->confirmationField,
]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/Dates/After.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public function passes(): bool
{
return Date::parse($this->getValue())->greaterThan($this->date);
}

public function message(): string|null
{
return trans('validation.date.after', ['field' => $this->getFieldForHumans()]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/Dates/AfterOrEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public function passes(): bool
{
return Date::parse($this->getValue())->greaterThanOrEqualTo($this->date);
}

public function message(): string|null
{
return trans('validation.date.after_or_equal', ['field' => $this->getFieldForHumans()]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/Dates/AfterOrEqualTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ public function passes(): bool

return Date::parse($date)->greaterThanOrEqualTo($relatedDate);
}

public function message(): string|null
{
return trans('validation.date.after_or_equal_to', [
'field' => $this->getFieldForHumans(),
'other' => $this->relatedField,
]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/Dates/AfterTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ public function passes(): bool

return Date::parse($date)->greaterThan($relatedDate);
}

public function message(): string|null
{
return trans('validation.date.after_to', [
'field' => $this->getFieldForHumans(),
'other' => $this->relatedField,
]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/Dates/Before.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public function passes(): bool
{
return Date::parse($this->getValue())->lessThan($this->date);
}

public function message(): string|null
{
return trans('validation.date.before', ['field' => $this->getFieldForHumans()]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/Dates/BeforeOrEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public function passes(): bool
{
return Date::parse($this->getValue())->lessThanOrEqualTo($this->date);
}

public function message(): string|null
{
return trans('validation.date.before_or_equal', ['field' => $this->getFieldForHumans()]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/Dates/BeforeOrEqualTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ public function passes(): bool

return Date::parse($date)->lessThanOrEqualTo($relatedDate);
}

public function message(): string|null
{
return trans('validation.date.before_or_equal_to', [
'field' => $this->getFieldForHumans(),
'other' => $this->relatedField,
]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/Dates/BeforeTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ public function passes(): bool

return Date::parse($date)->lessThan($relatedDate);
}

public function message(): string|null
{
return trans('validation.date.before_to', [
'field' => $this->getFieldForHumans(),
'other' => $this->relatedField,
]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/Dates/Equal.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public function passes(): bool
{
return Date::parse($this->getValue())->equalTo($this->date);
}

public function message(): string|null
{
return trans('validation.date.equal', ['field' => $this->getFieldForHumans()]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/Dates/EqualTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ public function passes(): bool

return $date->equalTo($relatedDate);
}

public function message(): string|null
{
return trans('validation.date.equal_to', [
'field' => $this->getFieldForHumans(),
'other' => $this->relatedField,
]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/Dates/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public function passes(): bool

return $dateTime instanceof DateTime;
}

public function message(): string|null
{
return trans('validation.date.format', ['field' => $this->getFieldForHumans(), 'format' => $this->format]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/Dates/IsDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public function passes(): bool
}

}

public function message(): string|null
{
return trans('validation.date.is_date', ['field' => $this->getFieldForHumans()]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/DoesNotEndWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public function passes(): bool
{
return ! parent::passes();
}

public function message(): string|null
{
return trans('validation.does_not_end_with', [
'field' => $this->getFieldForHumans(),
'values' => $this->needle,
]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/DoesNotStartWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public function passes(): bool
{
return ! parent::passes();
}

public function message(): string|null
{
return trans('validation.does_not_start_with', [
'field' => $this->getFieldForHumans(),
'values' => $this->needle,
]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/EndsWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public function passes(): bool
{
return str_ends_with($this->getValue(), $this->needle);
}

public function message(): string|null
{
return trans('validation.ends_with', [
'field' => $this->getFieldForHumans(),
'values' => $this->needle,
]);
}
}
7 changes: 7 additions & 0 deletions src/Validation/Rules/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ public function passes(): bool
->whereEqual($this->column ?? $this->field, $this->getValue())
->exists();
}

public function message(): string|null
{
return trans('validation.exists', [
'field' => $this->getFieldForHumans(),
]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ public function passes(): bool
{
return in_array($this->getValue(), $this->haystack, true);
}

public function message(): string|null
{
return trans('validation.in', [
'field' => $this->getFieldForHumans(),
'values' => implode(', ', $this->haystack),
]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/IsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public function passes(): bool
{
return is_array($this->getValue());
}

public function message(): string|null
{
return trans('validation.array', ['field' => $this->getFieldForHumans()]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/IsBool.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public function passes(): bool
{
return in_array($this->getValue(), [true, false, 'true', 'false', 1, 0, '1', '0'], true);
}

public function message(): string|null
{
return trans('validation.boolean', ['field' => $this->getFieldForHumans()]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/IsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public function passes(): bool
&& array_is_list($value)
&& ! $this->isScalar($value);
}

public function message(): string|null
{
return trans('validation.collection', ['field' => $this->getFieldForHumans()]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/IsDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public function passes(): bool
&& ! array_is_list($value)
&& $this->isScalar($value);
}

public function message(): string|null
{
return trans('validation.dictionary', ['field' => $this->getFieldForHumans()]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/IsEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public function pusValidation(EmailValidation $emailValidation): self

return $this;
}

public function message(): string|null
{
return trans('validation.email', ['field' => $this->getFieldForHumans()]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/IsFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public function passes(): bool

return $value instanceof BufferedFile;
}

public function message(): string|null
{
return trans('validation.file', ['field' => $this->getFieldForHumans()]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/IsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ protected function isScalar(array $data): bool

return true;
}

public function message(): string|null
{
return trans('validation.list', ['field' => $this->getFieldForHumans()]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/IsString.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public function passes(): bool
{
return is_string($this->getValue());
}

public function message(): string|null
{
return trans('validation.string', ['field' => $this->getFieldForHumans()]);
}
}
5 changes: 5 additions & 0 deletions src/Validation/Rules/IsUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ public function passes(): bool
return parent::passes()
&& filter_var($this->getValue(), FILTER_VALIDATE_URL) !== false;
}

public function message(): string|null
{
return trans('validation.url', ['field' => $this->getFieldForHumans()]);
}
}
18 changes: 18 additions & 0 deletions src/Validation/Rules/Max.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,22 @@ public function passes(): bool
{
return $this->getValue() <= $this->limit;
}

public function message(): string|null
{
$value = $this->data->get($this->field) ?? null;
$type = gettype($value);

$key = match ($type) {
'string' => 'validation.max.string',
'array' => 'validation.max.array',
'object' => 'validation.max.file',
default => 'validation.max.numeric',
};

return trans($key, [
'field' => $this->getFieldForHumans(),
'max' => $this->limit,
]);
}
}
8 changes: 8 additions & 0 deletions src/Validation/Rules/Mimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ public function passes(): bool
{
return in_array($this->getValue()->getMimeType(), $this->haystack, true);
}

public function message(): string|null
{
return trans('validation.mimes', [
'field' => $this->getFieldForHumans(),
'values' => implode(', ', $this->haystack),
]);
}
}
18 changes: 18 additions & 0 deletions src/Validation/Rules/Min.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,22 @@ public function passes(): bool
{
return $this->getValue() >= $this->limit;
}

public function message(): string|null
{
$value = $this->data->get($this->field) ?? null;
$type = gettype($value);

$key = match ($type) {
'string' => 'validation.min.string',
'array' => 'validation.min.array',
'object' => 'validation.min.file',
default => 'validation.min.numeric',
};

return trans($key, [
'field' => $this->getFieldForHumans(),
'min' => $this->limit,
]);
}
}
Loading