New Middlewares in laravel 5.4

Laravel 5.4 Includes Two New Middleware.These are TrimStrings and ConvertEmptyStringsToNull.


1.Trim Strings Middleware

This middleware is user for trim a given srting.The main advantage of this middleware is it can be avoiding the problams of extra space from the user form data.

dd(request('name'));//'Morfin paul   '

Normally this will return 'Morfin paul ' if we type a extra space in the test box. but after enabling the Trim Strings Middleware we will get the result like

dd(request('name'));//'Morfin paul'

For enabling this feature just add below line to your protected $middleware array in App/Kernel.php.

\Illuminate\Foundation\Http\Middleware\TrimStrings::class,

2.Convert Empty Strings to Null Middleware

According to the name if using this middleware we can convert Empty Strings to Null.

dd(request('vat')); // ''

After using this middleware this can be work like this

dd(request('vat')); // null

For enabling this feature just add below line to your protected $middleware array in App/Kernel.php.

\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,