Laravel 5.4 is scheduled to be released next week, and it already includes many great new features, but the team was able to sneak in two new Middleware offerings. These are
Trim Strings Middleware
Just as the name suggests, the Trim Strings middleware will automatically trim all the request data so you don’t have to worry about those situations where someone may inadvertently add extra spaces in your form fields.
As an example let’s say you have a newsletter signup which requires an email address. Previously, if someone entered an extra space it would end up like this:
dd(request('email')); // 'email@example.com '
Now, by adding the TrimStrings middleware to App/Kernel.php:
protected $middleware = [ \Illuminate\Foundation\Http\Middleware\TrimStrings::class,
This would result in:
dd(request('email')); // 'firstname.lastname@example.org'
Convert Empty Strings to Null
Paired with the Trim Strings, is a new
ConvertEmptyStringsToNull which works in basically the same way. A good example is a form with a not required field that maps to a nullable database column.
As an example, pretend you have a VAT field for users to enter their tax code.
<input type="text" name="vat" value="">
If you left it blank prior, it would return an empty string:
dd(request('vat')); // ''
ConvertEmptyStringsToNull middleware this will now be null:
dd(request('vat')); // null
Join the weekly newsletter and never miss out on new tips, tutorials, and more.
- Senior Quality Assurance Engineer
- Senior PHP/Laravel Developer: Your Dream Work Environment
iPhone Photography School
- Senior Software Engineer
Remote or San Francisco
- Laravel Developer
Las Vegas, NV
- R&D Developer
- Full-Stack Developer
- Full Stack Developer
Automatically Making Monthly Payments with Dusk
Laravel Dusk is a new feature coming to Laravel 5.4 and even though that release isn’t out, people have started…
Laracon EU 2017 is Announced
The Laracon EU has just announced the dates and early bird ticket pricing for the 2017 conference. This year it will…