Enhance handling of form name attributes in dot and array notations
Overview:
This pull request introduces improvements to the way our Laravel application handles form name attributes that are presented in both dot notation and array notation. The modifications ensure that the framework can appropriately determine error messages and retrieve old input values regardless of the notation style used. This is crucial for maintaining user input data across form submissions, especially in scenarios where validation errors occur.
Changes Made:
-
Normalization of Dot Notation:
- Updated the
foreach
loop handling parameters to check if thename
key needs to be normalized from dot notation (e.g.,test.hello.world
) to array notation (e.g.,test[hello][world]
). This ensures compatibility with HTML form name attributes and simplifies handling in subsequent backend processes. - Utilized
array_map
andarray_slice
to dynamically construct the array-style name string from the dot notation.
- Updated the
-
Retrieval of Old Input Values:
- Implemented the
retrieveOldValue
method to fetch the previous input values using Laravel'sold()
helper. This method first converts a name from array notation back to dot notation to match the expected
- Implemented the
-
Conversion from Array to Dot Notation for Error Handling:
- Developed the
convertQueryStingToDotNotation
static method to transform input names from array notation (e.g.,test[hello][world]
) back to dot notation (test.hello.world
). This conversion is crucial for correctly mapping validation errors to their associated form fields, as Laravel's validation errors typically utilize dot notation to reference the fields. - The method uses PHP's
parse_str
to decode the string notation into an associative array, then leverages Laravel'sArr::dot()
method to flatten the array back into a dot notation string. This ensures that even nested array inputs are properly converted and recognized by the validation error handler.
- Developed the
Additional Notes:
While the changes introduced have passed the existing tests, it's important to note that our test coverage may not extensively cover all edge cases related to these form name conversions. Therefore, I would highly appreciate a thorough review by the repository maintainer to ensure that these modifications align well with existing functionalities and to discuss any potential improvements.
I am fully open to feedback and necessary changes recommended during your review to better accommodate use cases that might not have been sufficiently tested or considered.
Looking forward to your insights and suggestions to refine this update further.