Skip to content
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] ConvertEmptyStringsToNull not working with 'sometimes' validation rule #17807

Closed
bkremenovic opened this issue Feb 7, 2017 · 7 comments

Comments

@bkremenovic
Copy link

  • Laravel Version: 5.4.x
  • PHP Version: 7.0.13
  • Database Driver & Version: N/A

Description:

There is a bug in a new Laravel's 5.4 middleware ConvertEmptyStringsToNull when using sometimes validation rule.

Steps To Reproduce:

$this->validate($request, [
    "firstname"     => "sometimes|max:50",
], [	
    "firstname.max" => "Ime ne smije sadržati više od :max karaktera !",
]);

Try removing \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, in Kernel.php. It works, then.

@bkremenovic bkremenovic changed the title [5.4] ConvertEmptyStringsToNull not workin with 'sometimes' validatio nrule [5.4] ConvertEmptyStringsToNull not working with 'sometimes' validation rule Feb 7, 2017
@tillkruss
Copy link
Contributor

What happens if you add nullable to firstname?

@ankurk91
Copy link
Contributor

ankurk91 commented Feb 7, 2017

The sometimes validation checks if that input present in $_POST array and if yes then it proceed with more validations.
sometimes won't make form field optional.
See issue #17663
Also check the note about optional field on Laravel Docs

@themsaid
Copy link
Member

themsaid commented Feb 7, 2017

@ongulus what's in $request, there's no way we can help without knowing the input you use to test.

@srmklive
Copy link
Contributor

srmklive commented Feb 8, 2017

@ongulus Can you specify the contents of the $request?

@themsaid
Copy link
Member

themsaid commented Feb 9, 2017

Closing for lack of activity.

@themsaid themsaid closed this as completed Feb 9, 2017
@bkremenovic
Copy link
Author

The $request contains "firstname" POST field from

@bkremenovic
Copy link
Author

Not a bug, but a feature :) According to Laravel's documentation - https://laravel.com/docs/5.4/validation#rule-nullable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants