Skip to content

Commit

Permalink
Refactoring and added placeholder support
Browse files Browse the repository at this point in the history
New syntax [The :name field is required]
  • Loading branch information
SkyWalkerGhost committed Sep 12, 2024
1 parent 74a21e4 commit bc63120
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 40 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to `shergela/validation-rule` will be documented in this file.

## 1.0.7 | 12 September - 2024
- Refactoring code.
- Added support for substitutions in messages, This is needed to be able to write good messages.
Placeholder will allow you to write messages using positioning.
- New syntax for messages "The :name field is required.", or "The :email field is required."


## 1.0.6 | 06 September - 2024

- add new `uppercaseWord()` method.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Build custom laravel validation rules easily

> This package is under development, please do not use in production.
> You can download and test it.
## Installation
Require the package with composer using the following command:

Expand Down
4 changes: 2 additions & 2 deletions src/Constants/ValidationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class ValidationRule
/**
* The field under validation must be included in the given list of values in:foo,bar...
*/
public const IN = 'in:';
public const IN = 'in';

/**
* The field under validation must not be included in the given list of values not_in:foo,bar,bar...
*/
public const NOT_IN = 'not_in:';
public const NOT_IN = 'not_in';
}
1 change: 0 additions & 1 deletion src/Rules/SeparateIntegersByComma.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Str;
use Shergela\Validations\Constants\ValidationRegex as Regex;

class SeparateIntegersByComma implements ValidationRule
Expand Down
1 change: 0 additions & 1 deletion src/Rules/SeparateStringsByComma.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Str;
use Shergela\Validations\Constants\ValidationRegex as Regex;

class SeparateStringsByComma implements ValidationRule
Expand Down
1 change: 0 additions & 1 deletion src/Rules/SeparateStringsByUnderscore.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Str;
use Shergela\Validations\Constants\ValidationRegex as Regex;

class SeparateStringsByUnderscore implements ValidationRule
Expand Down
6 changes: 4 additions & 2 deletions src/Validation/BuildValidationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class BuildValidationRule
/**
* @var bool
*/
protected ?bool $distinctStinct = false;
protected ?bool $distinctStrict = false;

/**
* @var bool
Expand Down Expand Up @@ -468,8 +468,10 @@ protected function buildValidationRules(): array
? [DateRule::DATE_BEFORE_OR_EQUAL . $this->dateBeforeOrEqual]
: []
),

...($this->dateAfterOrEqualToday === true ? [DateRule::DATE_AFTER_OR_EQUAL_TODAY] : []),
...($this->dateAfter !== null ? [DateRule::DATE_AFTER . $this->dateAfter] : []),

...($this->dateAfterOrEqual !== null
? [DateRule::DATE_AFTER_OR_EQUAL . $this->dateAfterOrEqual]
: []
Expand Down Expand Up @@ -507,7 +509,7 @@ protected function buildValidationRules(): array
*/
...($this->array === true ? [ArrayRule::ARRAY] : []),
...($this->arrayDistinct === true ? [ArrayRule::DISTINCT] : []),
...($this->distinctStinct === true ? [ArrayRule::DISTINCT_STRICT] : []),
...($this->distinctStrict === true ? [ArrayRule::DISTINCT_STRICT] : []),
...($this->distinctIgnoreCase === true ? [ArrayRule::DISTINCT_IGNORE_CASE] : []),
];

Expand Down
Loading

0 comments on commit bc63120

Please sign in to comment.