Strange behaviour with string property validation
emsifa opened this issue · comments
Muhammad Syifa commented
For example we have DTO like this:
class SomethingDto extends Dto
{
public string $message;
}
When we send data below:
{
"message": ""
}
It results an error "Message must be a string".
Expectation
It should not error because an empty string is a string.
Muhammad Syifa commented
So, this happens because by default in app/Http/Kernel.php
Laravel enable \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class
middleware which converts an empty string to null. If we want our DTO accepts empty strings, we have to notice user to disable the middleware.