2
votes

I have upgraded Laravel from the 5.3 to the 5.4 version, however, if I have an empty value in a text input when I submit the form I have now a NULL value instead of an empty one, and this did not happen with the 5.3 version.

I have now to forcely set a nullable or required validation rules, how can I solve this issue?

2

2 Answers

2
votes

In Laravel 5.4, two new middlewares were included TrimStrings and ConvertEmptyStringsToNull.

In effect, for every form request, Laravel will automatically trim any white space, while also converting all empty request fields to null.

If you want to disable these then simply comment both in your app/Http/Kernel.php.

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
    // \App\Http\Middleware\TrimStrings::class,
    // \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
0
votes

In Laravel 5.4, there is a middleware TrimStrings which trims all empty values.

You could disable it from app/Http/Kernel.php.

Just remove \App\Http\Middleware\TrimStrings::class, from the middleware array.