Skip to content

Commit 9187d5b

Browse files
committed
Check for empty value
1 parent 4548850 commit 9187d5b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Rules/DivisibleBy.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Arifszn\AdvancedValidation\Rules;
44

55
use Illuminate\Contracts\Validation\Rule;
6+
use Illuminate\Support\Facades\Validator;
67

78
/**
89
* The field under validation must be divisible by another.
@@ -50,7 +51,12 @@ public function passes($attribute, $value)
5051
{
5152
$this->attribute = $attribute;
5253

53-
return (floatval($value) !== 0.0) && (fmod(floatval($value), intval($this->number, 10)) === 0.0);
54+
$floatValidation = Validator::make(
55+
['float' => $value],
56+
['float' => ['required', new FloatNumber()]],
57+
);
58+
59+
return !$floatValidation->fails() && (fmod(floatval($value), intval($this->number, 10)) === 0.0);
5460
}
5561

5662
/**

src/Rules/FloatNumber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function passes($attribute, $value)
3838
{
3939
$regex = '/^(?:[-+])?(?:[0-9]+)?(?:\\.[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$/';
4040

41-
if ($value === '' || $value === '.' || $value === '-' || $value === '+') {
41+
if (!$value || $value === '.' || $value === '-' || $value === '+') {
4242
return false;
4343
}
4444

0 commit comments

Comments
 (0)