-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.4] Validator rules failing when using ConvertEmptyStringsToNull middleware #17558
Comments
If you use this middleware you say that you want to convert all empty strings to null, you'll need to prepare your rules for this change, use the |
@irsyadadl You need to add <?php
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required',
'website-url' => 'nullable|url',
]);
dd('Valid data sent');
} |
Swapping out 'sometimes' for 'nullable' fixed this for me when using the ConvertEmptyStringsToNull middleware |
Couldn't find anything in upgrade guide. Glad I found this issue. |
Description:
When using the new
ConvertEmptyStringsToNull
middleware, validator rules will fail for empty fields.Steps To Reproduce:
Take for example a two input form, asking for the user's name and website URL. The name is required but the URL is optional. When posted, the form validator may look like this:
If you submit the form with only a name filled out and a blank
website-url
field, the validator will fail saying that thenull
value of$request->input('website-url')
is not a valid URL. The validator should not be checking for a valid URL since the field is not required.The text was updated successfully, but these errors were encountered: