add new rule validation
This commit is contained in:
1 parent
4e262138a3
commit
f7562f91b9
18 files changed
+878
-41
No files matched your search
+119
-12
@@ -19,6 +19,34 @@ class JalaliValidator
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validateDateEqual($attribute, $value, $parameters)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->eq($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function validateDateNotEqual($attribute, $value, $parameters)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->ne($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function validateDateTime($attribute, $value, $parameters)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
@@ -34,6 +62,34 @@ class JalaliValidator
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validateDateTimeEqual($attribute, $value, $parameters)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->eq($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function validateDateTimeNotEqual($attribute, $value, $parameters)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->ne($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function validateDateAfter($attribute, $value, $parameters)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
@@ -42,7 +98,21 @@ class JalaliValidator
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->greaterThan($base);
|
||||
return Verta::parseFormat($format, $value)->gt($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function validateDateAfterEqual($attribute, $value, $parameters)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->gte($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
@@ -56,7 +126,21 @@ class JalaliValidator
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->greaterThan($base);
|
||||
return Verta::parseFormat($format, $value)->gt($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function validateDateTimeAfterEqual($attribute, $value, $parameters)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->gte($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
@@ -70,7 +154,21 @@ class JalaliValidator
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->lessThan($base);
|
||||
return Verta::parseFormat($format, $value)->lt($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function validateDateBeforeEqual($attribute, $value, $parameters)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->lte($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
@@ -84,23 +182,32 @@ class JalaliValidator
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->lessThan($base);
|
||||
return Verta::parseFormat($format, $value)->lt($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function replaceDate($message, $attribute, $rule, $parameters)
|
||||
public function validateDateTimeBeforeEqual($attribute, $value, $parameters)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||
try {
|
||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||
return Verta::parseFormat($format, $value)->lte($base);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function replaceDateOrDatetime($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function replaceDatetime($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function replaceDateAfterOrBefore($message, $attribute, $rule, $parameters)
|
||||
public function replaceDateAfterOrBeforeOrEqual($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||
$date = count($parameters) ? $parameters[0] : Verta::instance()->format($format);
|
||||
@@ -108,7 +215,7 @@ class JalaliValidator
|
||||
return str_replace([':date', ':fa-date'], [$date, $faDate], $message);
|
||||
}
|
||||
|
||||
public function replaceDateTimeAfterOrBefore($message, $attribute, $rule, $parameters)
|
||||
public function replaceDateTimeAfterOrBeforeOrEqual($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||
$date = count($parameters) ? $parameters[0] : Verta::instance()->format($format);
|
||||
|
||||
@@ -43,17 +43,33 @@ class VertaServiceProvider extends ServiceProvider
|
||||
protected function validator()
|
||||
{
|
||||
Validator::extend('jdate', JalaliValidator::class . '@validateDate');
|
||||
Validator::extend('jdate_equal', JalaliValidator::class . '@validateDateEqual');
|
||||
Validator::extend('jdate_not_equal', JalaliValidator::class . '@validateDateNotEqual');
|
||||
Validator::extend('jdatetime', JalaliValidator::class . '@validateDateTime');
|
||||
Validator::extend('jdatetime_equal', JalaliValidator::class . '@validateDateTimeEqual');
|
||||
Validator::extend('jdatetime_not_equal', JalaliValidator::class . '@validateDateTimeNotEqual');
|
||||
Validator::extend('jdate_after', JalaliValidator::class . '@validateDateAfter');
|
||||
Validator::extend('jdate_after_equal', JalaliValidator::class . '@validateDateAfterEqual');
|
||||
Validator::extend('jdatetime_after', JalaliValidator::class . '@validateDateTimeAfter');
|
||||
Validator::extend('jdatetime_after_equal', JalaliValidator::class . '@validateDateTimeAfterEqual');
|
||||
Validator::extend('jdate_before', JalaliValidator::class . '@validateDateBefore');
|
||||
Validator::extend('jdate_before_equal', JalaliValidator::class . '@validateDateBeforeEqual');
|
||||
Validator::extend('jdatetime_before', JalaliValidator::class . '@validateDateTimeBefore');
|
||||
Validator::extend('jdatetime_before_equal', JalaliValidator::class . '@validateDateTimeBeforeEqual');
|
||||
|
||||
Validator::replacer('jdate', JalaliValidator::class . '@replaceDate');
|
||||
Validator::replacer('jdatetime', JalaliValidator::class . '@replaceDateTime');
|
||||
Validator::replacer('jdate_after', JalaliValidator::class . '@replaceDateAfterOrBefore');
|
||||
Validator::replacer('jdatetime_after', JalaliValidator::class . '@replaceDateTimeAfterOrBefore');
|
||||
Validator::replacer('jdate_before', JalaliValidator::class . '@replaceDateAfterOrBefore');
|
||||
Validator::replacer('jdatetime_before', JalaliValidator::class . '@replaceDateTimeAfterOrBefore');
|
||||
Validator::replacer('jdate', JalaliValidator::class . '@replaceDateOrDatetime');
|
||||
Validator::replacer('jdate_equal', JalaliValidator::class . '@replaceDateAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdate_not_equal', JalaliValidator::class . '@replaceDateAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdatetime', JalaliValidator::class . '@replaceDateOrDatetime');
|
||||
Validator::replacer('jdatetime_equal', JalaliValidator::class . '@replaceDateTimeAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdatetime_not_equal', JalaliValidator::class . '@replaceDateTimeAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdate_after', JalaliValidator::class . '@replaceDateAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdate_after_equal', JalaliValidator::class . '@replaceDateAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdatetime_after', JalaliValidator::class . '@replaceDateTimeAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdatetime_after_equal', JalaliValidator::class . '@replaceDateTimeAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdate_before', JalaliValidator::class . '@replaceDateAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdate_before_equal', JalaliValidator::class . '@replaceDateAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdatetime_before', JalaliValidator::class . '@replaceDateTimeAfterOrBeforeOrEqual');
|
||||
Validator::replacer('jdatetime_before_equal', JalaliValidator::class . '@replaceDateTimeAfterOrBeforeOrEqual');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'jdate' => 'The :attribute is not valid Jalali date',
|
||||
'jdate_equal' => 'The :attribute is not equal Jalali date :date',
|
||||
'jdate_not_equal' => 'The :attribute is\'nt not equal Jalali date :date',
|
||||
'jdatetime' => 'The :attribute is not valid Jalali datetime',
|
||||
'jdatetime_equal' => 'The :attribute is not equal Jalali datetime :date',
|
||||
'jdatetime_not_equal' => 'The :attribute is\'nt not equal Jalali datetime :date',
|
||||
'jdate_after' => 'The :attribute must be a Jalali date after :date.',
|
||||
'jdate_after_equal' => 'The :attribute must be a Jalali date after or equal :date.',
|
||||
'jdatetime_after' => 'The :attribute must be a Jalali datetime after :date.',
|
||||
'jdatetime_after_equal' => 'The :attribute must be a Jalali datetime after or equal :date.',
|
||||
'jdate_before' => 'The :attribute must be a Jalali date before :date.',
|
||||
'jdate_before_equal' => 'The :attribute must be a Jalali date before or equal :date.',
|
||||
'jdatetime_before' => 'The :attribute must be a Jalali datetime before :date.',
|
||||
'jdatetime_before_equal' => 'The :attribute must be a Jalali datetime before or equal :date.',
|
||||
];
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.',
|
||||
'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':fa-date' . ' نمی باشد.',
|
||||
'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':fa-date' . ' نمی باشد.',
|
||||
'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.',
|
||||
'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':fa-date' . ' نمی باشد.',
|
||||
'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':fa-date' . ' نمی باشد.',
|
||||
'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':fa-date' . ' باشد.',
|
||||
'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':fa-date' . ' باشد.',
|
||||
'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':fa-date' . ' باشد.',
|
||||
'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':fa-date' . ' باشد.',
|
||||
'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':fa-date' . ' باشد.',
|
||||
'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':fa-date' . ' باشد.',
|
||||
'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':fa-date' . ' باشد.',
|
||||
'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':fa-date' . ' باشد.',
|
||||
];
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'jdate' => 'The :attribute is not valid Jalali date',
|
||||
'jdatetime' => 'The :attribute is not valid Jalali datetime',
|
||||
'jdate_after' => 'The :attribute must be a Jalali date after :date.',
|
||||
'jdatetime_after' => 'The :attribute must be a Jalali datetime after :date.',
|
||||
'jdate_before' => 'The :attribute must be a Jalali date before :date.',
|
||||
'jdatetime_before' => 'The :attribute must be a Jalali datetime before :date.',
|
||||
];
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.',
|
||||
'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.',
|
||||
'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':fa-date' . ' باشد.',
|
||||
'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':fa-date' . ' باشد.',
|
||||
'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':fa-date' . ' باشد.',
|
||||
'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':fa-date' . ' باشد.',
|
||||
];
|
||||
Reference in new issue
Block a user