Laravel 5.3 Validation Fails when Variables are Null
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Title: Understanding Laravel 5.3 Validation Behavior with Null Values and Missing Parameters
Recently, you have faced some odd issues when upgrading your Laravel application from version 5.1 to 5.3 regarding the validation process. This blog post aims at addressing these peculiarities and providing a comprehensive understanding of how Laravel 5.3 handles null values and missing parameters in the validation process.
First, let's discuss why validation fails when variables are not set as required but hold null values:
1. In Laravel 5.3, the default rule for all fields is 'nullable', which means that these fields do not require any input to validate successfully. However, in your case, you have explicitly defined a rule for each field. The validation fails because the null value does not match the specified rule for the given field, even though it doesn't require a non-null value.
To resolve this issue, you can either remove the validation rules or update them to accept null values as valid inputs. For example:
$validator = Validator::make($postData, [
'firstName' => 'nullable|string|max:255',
'lastName' => 'nullable|string|max:255'
]);
Secondly, the validation fails when the value is set as null for a non-nullable field. This happens because you have assigned a specific rule for that field, which does not allow null values. The best practice in this case would be to explicitly define the 'nullable' rule if you intend to accept null values for any field.
Lastly, regarding parameters not being sent at all, such as the missing 'lastName', Laravel follows a similar behavior. In your previous version (5.1), these fields were automatically ignored during validation since they were not provided in the request. However, with Laravel 5.3's introduction of default nullable fields for all parameters, you need to explicitly define your required fields or set them as 'nullable'.
To ensure proper validation behavior with missing parameters:
1. For required fields, make sure that they are sent along with the request using form input or API request body. Otherwise, Laravel will fail the validation due to null values for those fields.
2. If you want to accept null values in your forms, define the 'nullable' rule for these fields. This allows Laravel to ignore the null values and still pass the validation process successfully.
In summary:
- Laravel 5.3 has introduced default nullable rules for all parameters, but you can override them by defining specific rules based on your requirements.
- Ensure that required parameters are sent with the request or explicitly define them as 'nullable'.
- For any issues related to validation with null values or missing parameters in the Laravel 5.3 validation process, follow the guidelines outlined above and adjust your application's configuration accordingly.