Skip to content

Commit

Permalink
Merge pull request #177 from RonasIT/77-list-exists-change-message
Browse files Browse the repository at this point in the history
fix: list_exists refactor message
  • Loading branch information
DenTray authored Jan 9, 2025
2 parents ffb76d3 + 1d35447 commit 9a0cd74
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/HelpersServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ protected function extendValidator(): void

Validator::extend('list_exists', function ($attribute, $value, $parameters, $validator) {
if (count($parameters) < 1) {
throw new InvalidValidationRuleUsageException('You must add at least 1 parameter.');
throw new InvalidValidationRuleUsageException("list_exists: At least 1 parameter must be added when checking the {$attribute} field in the request.");
}

$hasFieldNameParam = !empty(Arr::get($parameters, 2));

if (is_multidimensional($value) && !$hasFieldNameParam) {
throw new InvalidValidationRuleUsageException('The third argument should be filled for collections input.');
throw new InvalidValidationRuleUsageException("list_exists: The third parameter should be filled when checking the {$attribute} field if we are using a collection in request.");
}

if ($hasFieldNameParam) {
Expand Down
4 changes: 2 additions & 2 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function testListExistsFailedValidation()
public function testListExistsWithoutArgs()
{
$this->expectException(InvalidValidationRuleUsageException::class);
$this->expectExceptionMessage('You must add at least 1 parameter.');
$this->expectExceptionMessage('list_exists: At least 1 parameter must be added when checking the ids field in the request.');

$validator = Validator::make(
['ids' => [1, 2, 3]],
Expand All @@ -149,7 +149,7 @@ public function testListExistsWithoutArgs()
public function testListExistsIncorrectParameters()
{
$this->expectException(InvalidValidationRuleUsageException::class);
$this->expectExceptionMessage('The third argument should be filled for collections input.');
$this->expectExceptionMessage('The third parameter should be filled when checking the ids field if we are using a collection in request.');

$validator = Validator::make(
[
Expand Down

0 comments on commit 9a0cd74

Please sign in to comment.