Propaganistas / Laravel-Phone

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

Should be able to make the phone number optional #90

Closed flap152 closed 6 years ago

flap152 commented 6 years ago

I successfully used the package to validate phone numbers when present, but in some forms the field is optional. Here is my rules statement:

    public function rules()
    {
        return [
            'email' => 'required|email|max:191',
            'sms' =>   'phone:AUTO,US|max:191',
            'first_name'  => 'max:191',
            'last_name'  => 'required|max:191',
            'timezone' => 'required|max:191',
            'roles' => 'required|array',
        ];
    }

Notice how some fields have the required rule on laravel "native" validators to state the intent? We should be able to tell the package to ignore empty inputs. Actually, it should only complain if we used required but I guess you'll resist a breaking change like that ;-) An alternative could be a NULL option such as phone:AUTO,US,NULL

Propaganistas commented 6 years ago

Use Laravel's built-in "nullable" validator.