Issue with required() Function When Using Callback for Validation

PhoneInput::make('phone') ->inputNumberFormat(PhoneInputNumberType::E164) ->strictMode(true) ->required(function (Get $get) { return is_null(($this->selectedRowId)) && empty($get('email')); }) ->rules([ new UniquePhone(), 'regex:/^(?:\D\d\D){10,}$/', ]) ->validationMessages([ 'required' => "Either phone or email is required.", 'regex' => "The phone number must contain at least 10 digits.", ]) ->separateDialCode(true) ->autoPlaceholder('off') ->countryOrder(['us']) ->initialCountry('us'), I'm facing an issue with the required() function in the package. It works correctly when I pass a direct false value, but when I use a callback function that returns false under certain conditions, the validation still prompts for a value instead of properly skipping the required check. I’ve confirmed that the callback function returns false as expected, but it doesn't seem to be triggering the required validation logic. Can anyone provide insight or guidance on how to properly use the required() function with a callback to conditionally bypass validation? Any help would be greatly appreciated! I am sharing the code for reference.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?