[9.x] Added argument transformNullToEmptyString to the functions old() and … #35853
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…getOldInput() and added tests
I implemented this feature: laravel/ideas#1826
Basically I modified the old() and getOldInput() functions to work nicely with the ConvertEmptyStringsToNull middleware. At the moment when you are making an update form (or a create form with a default non empty value) you can't use the old() helper function. Because if a specific field already has a value and the user removes this value in the form, the empty value is overridden with the existing value (or the default value). Which is not the intended behavior and makes the old() function rather useless at the moment. The only way to properly use the old() function at the moment is by not using the ConvertEmptyStringsToNull middleware. But this is a default middleware so in my opinion it makes sense that the old() function can handle this properly.
This shouldn't break anything. I added a default value of false and the tests are all working. I also added some extra tests (asserts) cases that weren't covered yet and added tests for the new feature itself.
Personally I think it would make sense to make the default value equal true. But this would be a breaking change, that's why I used false.