Table of Contents

With the release of 5.4, two new middlewares are now shipped with the framework. If you don't know what middlewares are, check out Understanding Laravel Middlewares.

The middlewares are:

Trim Strings Middleware

Just as the name implies, this middleware trims extra spaces from request data. For example, a user submits their email through a form on your website and mistakenly types in some extra space after the email.

This middleware will automatically trim whitespace, so if a user submits something like this.

// 'demo@example.org '

Because of the existence of this middleware (\Illuminate\Foundation\Http\Middleware\TrimStrings::class) in App/Kernel.php, it gets converted into.

// 'demo@example.org'

Convert Empty Strings to Null

Still, as the name implies, this middleware converts empty strings to null. So if a user submits an empty form instead of getting '' it gets converted to null.

// Loop through all the posts and schedule them for sharing to twitter$posts->each(function($post){return$post->schedule(TWITTER);});

With High order messages in Laravel, we can simplify the above code into this.

$posts->each->schedule(TWITTER);

Yes, this is now a possibility. It doesn't just stop here either, we can take this a bit further and chain them. Here, another scenario.

/**
* Loop through all the posts and reject any archived post
* Then for the remaining posts, schedule each of them to twitter.
*/$posts->reject(function($post){return$post->archived;})->each(function($post){return$post->schedule(TWITTER);});

With high order messages, we can simplify the above code into this.

Free Node eBook

Build your first Node apps and learn server-side JavaScript.

📧

Nice!

Check your email to confirm your subscription.

$posts->reject->archived->each->schedule(TWITTER);

Want to see how it's done, check out this commit. This is simply mindblowing

Laravel Elixir provided us with a gulp wrapper that made development and packaging of assets easier.

The next version of Laravel Elixir is changing the underlying system and will be built on Webpack, instead of Gulp. This will replace the plugin ecosystem, and because of such a significant change, it was time to rename the package.

Also, Laravel Mix comes with a new helper function called mix() that serves as a replacement to the former elixir() function.

If you have a project still using Elixir, you can continue using it, as it is still supported and not going anywhere anytime soon.

Facades provide a “static” interface to classes that are available in the application’s service container. Laravel ships with many facades which provide access to almost all of Laravel’s features. Laravel facades serve as “static proxies” to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.

One example that comes to mind is Auth. In laravel, we access an authenticated user's data by doing Auth::user(). This Auth class is a facade.

Now in Laravel 5.4, we can create facades on the fly. All we need do is namespace class on the Facade namespace and we can use the class as a facade.

Laravel Dusk provides an expressive, easy-to-use browser automation and testing API. By default, Dusk does not require you to install JDK or Selenium on your machine. Instead, Dusk uses a standalone ChromeDriver installation. However, you are free to utilise any other Selenium compatible driver you wish.

Basically, it means we can test our Laravel code like we would in a web browser. Currently, Laravel uses browser-kit for testing.

The problem with browser-kit is that it is limited, and Dusk serves as an alternative with more features.

Dusk can detect AJAX etc. A full-length article on Dusk is on the way, stay tuned.

Laravel 5.4 made a change to the default database character set, and it’s now utf8mb4 which includes support for storing emojis. This only affects new applications and as long as you are running MySQL v5.7.7 and higher you do not need to do anything.

For those running MariaDB or older versions of MySQL you may hit this error when trying to run migrations:

From the moment you publish a website, you need to be wary of security. From hackers to script-kiddies, you can’t always be sure of where the next attack could come from. So, as developers, we are always on the prowl for the next best thing when it comes to protecting our website(s)....