Propaganistas / Laravel-Phone

Phone number functionality for Laravel
https://laravel-phone.herokuapp.com/
MIT License
2.7k stars 214 forks source link

Nullable rule being ignored #171

Closed njwela closed 3 years ago

njwela commented 3 years ago

tried to put the phone number as an optional field but the nullable rule is still being ignore. Have tried the heroku demo app and its showing the same result

image

Is there a way for me to make the phone number field optional or this is a bug in the package

Propaganistas commented 3 years ago

Hi there

Did you set up your validation rules correctly?

This test shows that everything should work just fine: https://github.com/Propaganistas/Laravel-Phone/blob/0a16a46189bc88ced536c36047bf3b1018056139/tests/PhoneValidatorTest.php#L575-L581

( FYI: The demo app is set up to always require a value. I don't think a comparison can be made in that sense. )

njwela commented 3 years ago

These are my rules

$validator = Validator::make($req->all(), [ 'category' => ['required'], 'location' => ['required'], 'address' => ['required', 'string', 'max:100'], 'title' => ['required', 'string', 'max:100'], 'description' => ['string', 'max:200'], 'case_image' => ['max:1024', 'mimes:jpeg,bmp,png'], 'phone_number' => ['nullable','phone:ZW'], 'addr_lat' => ['required'], 'addr_lng' => ['required'] ]);

Propaganistas commented 3 years ago

Your validation rule looks fine. You could try to inspect the actual received value using dd($req->input('phone_number').

njwela commented 3 years ago

If i dont enter anything, it returns null, if i do, return anything i put in the field

Propaganistas commented 3 years ago

I'm afraid I can't help you as the package works fine. The automated test passes and I'm using the nullable/phone validation rule combination myself in several projects without any problems.

tanogalego commented 5 months ago

This is still an issue at laravel-phone version "^5.1". The test passes but the 'nullable' rule is ignored.

return [
    'phone' => ['nullable', 'phone:INTERNATIONAL,US'],
];

The above code returns always an error when a null value is sent on the $request->phone field.

This issue should be OPEN.