fix(rule): memperbaiki rule UnsignedInteger dan menyesuaikan validasi angka
This commit is contained in:
parent
ed7ffd0d41
commit
42df909c3f
@ -33,9 +33,9 @@ public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:50'],
|
||||
'size' => ['required', 'numeric', new UnsignedInteger],
|
||||
'cost_price' => ['required', 'numeric', new UnsignedInteger],
|
||||
'sale_price' => ['required', 'numeric', new UnsignedInteger],
|
||||
'size' => ['required', new UnsignedInteger],
|
||||
'cost_price' => ['required', new UnsignedInteger],
|
||||
'sale_price' => ['required', new UnsignedInteger],
|
||||
'description' => ['nullable', 'string'],
|
||||
'outlet_ids' => ['required', 'array', 'min:1'],
|
||||
'outlet_ids.*' => Rule::exists('outlets', 'id'),
|
||||
|
||||
@ -53,8 +53,8 @@ public function rules(): array
|
||||
Rule::unique('perfumes', 'sku')->ignore($this->perfume),
|
||||
],
|
||||
'brand' => ['nullable', Rule::exists('brands', 'id')],
|
||||
'cost_price' => ['required', 'numeric', new UnsignedInteger],
|
||||
'sale_price' => ['required', 'numeric', new UnsignedInteger],
|
||||
'cost_price' => ['required', new UnsignedInteger],
|
||||
'sale_price' => ['required', new UnsignedInteger],
|
||||
'base_notes' => ['nullable', 'string', 'max:255'],
|
||||
'middle_notes' => ['nullable', 'string', 'max:255'],
|
||||
'top_notes' => ['nullable', 'string', 'max:255'],
|
||||
|
||||
@ -39,8 +39,8 @@ public function rules(): array
|
||||
'max:20',
|
||||
Rule::unique('products', 'sku')->ignore($this->product),
|
||||
],
|
||||
'cost_price' => ['required', 'numeric', new UnsignedInteger],
|
||||
'sale_price' => ['required', 'numeric', new UnsignedInteger],
|
||||
'cost_price' => ['required', new UnsignedInteger],
|
||||
'sale_price' => ['required', new UnsignedInteger],
|
||||
'description' => ['nullable', 'string'],
|
||||
'outlet_ids' => ['required', 'array', 'min:1'],
|
||||
'outlet_ids.*' => Rule::exists('outlets', 'id'),
|
||||
|
||||
@ -24,7 +24,7 @@ public function rules(): array
|
||||
{
|
||||
return [
|
||||
'description' => ['required', 'string', 'max:100'],
|
||||
'amount' => ['required', 'numeric', new UnsignedInteger],
|
||||
'amount' => ['required', new UnsignedInteger],
|
||||
'image' => ['nullable', 'array'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -57,19 +57,19 @@ public function rules(): array
|
||||
Rule::when(
|
||||
fn () => $this->type == VoucherType::PERCENTAGE->value,
|
||||
['integer', 'between:0,100'],
|
||||
['numeric', new UnsignedInteger],
|
||||
[new UnsignedInteger],
|
||||
),
|
||||
],
|
||||
'min_purchase' => ['nullable', 'numeric', new UnsignedInteger],
|
||||
'min_purchase' => ['nullable', new UnsignedInteger],
|
||||
'max_discount' => [
|
||||
Rule::when(
|
||||
fn () => $this->type == VoucherType::PERCENTAGE->value,
|
||||
['required', 'numeric', new UnsignedInteger],
|
||||
['required', new UnsignedInteger],
|
||||
['nullable'],
|
||||
),
|
||||
],
|
||||
'quota' => ['nullable', 'numeric', new UnsignedInteger],
|
||||
'limit_per_user' => ['nullable', 'numeric', new UnsignedInteger],
|
||||
'quota' => ['nullable', new UnsignedInteger],
|
||||
'limit_per_user' => ['nullable', new UnsignedInteger],
|
||||
'start_date' => ['required', 'date'],
|
||||
'end_date' => ['nullable', 'date', 'after_or_equal:start_date'],
|
||||
'terms_conditions' => ['nullable', 'string'],
|
||||
|
||||
@ -45,7 +45,7 @@ public function rules(): array
|
||||
'username' => ['required', 'alpha_num', 'min:5', 'max:20', Rule::unique('users', 'username')->ignore($this->user)],
|
||||
'email' => ['required', 'email', 'max:100', Rule::unique('users', 'email')->ignore($this->user)],
|
||||
'phone_number' => ['required', 'string', new PhoneNumber],
|
||||
'base_salary' => ['required', 'regex:/^[0-9.]+$/', new UnsignedInteger],
|
||||
'base_salary' => ['required', new UnsignedInteger],
|
||||
'birthdate' => ['required', 'date', 'before:'.Carbon::now()->subYears(18)->format('Y-m-d')],
|
||||
'hire_date' => ['required', 'date'],
|
||||
'address' => ['required', 'string'],
|
||||
|
||||
@ -9,14 +9,18 @@ class UnsignedInteger implements ValidationRule
|
||||
{
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (! ctype_digit((string) $value)) {
|
||||
$fail("{$attribute} harus berupa bilangan bulat positif.");
|
||||
$normalized = str_replace('.', '', (string) $value);
|
||||
|
||||
if (! ctype_digit($normalized)) {
|
||||
$fail(':Attribute harus berupa bilangan bulat positif.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ((int) $value < 0 || (int) $value > 4294967295) {
|
||||
$fail("{$attribute} harus berada di antara 0 dan 4294967295.");
|
||||
$intValue = (int) $normalized;
|
||||
|
||||
if ($intValue < 0 || $intValue > 4294967295) {
|
||||
$fail(':Attribute harus berada di antara 0 dan 4.294.967.295.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user