The version 5.4 of Laravel PHP Framework was released this week and it’s full of interesting new features and improvements. Although we are already used to the constant innovation of this framework, 5.4 is one of the most interesting releases we have ever seen.

Main New Features:

Laravel Dusk

Dusk is an evolution of BrowserKit that uses ChromeDriver and the Facebook Php-webdriver instead of Symfony BrowserKit. This allows Dusk to support Javascript and be an end-to-end testing tool. Since it uses with ChromeDriver, it takes away the work of dealing JDK and the Selenium server.

Also, comes with a simple and easy to understand syntax:

$this->browse(function ($browser) use ($user) { $browser->loginAs($user) ->visit('/home') ->press('Create Playlist') ->whenAvailable('.playlist-modal', function ($modal) { $modal->type('name', 'My Playlist') ->press('Create'); }); $browser->waitForText('Playlist Created'); });

Read more on the docs.

Markdown Emails

With this new feature, it’s now possible to use Markdown to create you emails template. This templates will be rendered into responsive HTML templates for the messages while being easier to read and to maintain as a simple Markdown plain-text.

Blade Components and Slots

Blade components and slots provide basically same benefits as sections and layouts but they are a more easy and flexible way to create templates. If you’re familiar with Vue.js then this will feel pretty much the same.

<!-- /resources/views/alert.blade.php --> <div class="alert alert-danger"> {{ $slot }} </div> <!-- usage of alert component --> @component('alert') <strong>Whoops!</strong> Something went wrong! @endcomponent

Laravel Mix

Mix is the next version Elixir, with the main difference being that it is entirely based on Webpack instead of Gulp.

mix.js('resources/assets/js/app.js', 'public/js') .sass('resources/assets/sass/app.scss', 'public/css');

Route Improvements

Better fluent syntax to define a named route or a middleware:

Route::name('profile')->get('user/{id}/profile', function ($id) { // return user profile }); Route::middleware('auth')->prefix('api')->group(function () { // routes for this group }); Route::middleware('auth')->resource('user', 'UserController');

Higher Order Collection Messages

Collections now provide short-cuts (or “higher order messages”) to performing common actions on them. The supported collection methods are:

(contains, each, every, filter, first, map, partition, reject, sortBy, sortByDesc, sum)

Example:

// each example $users = User::where('votes', '>', 500)->get(); $users->each->markAsVip(); // sum example $users = User::where('group', 'Development')->get(); return $users->sum->votes;

Other Features and Improvements:

Among the many other features and improvements in this release, special attention for:

– New TrimStrings and ConvertEmptyStringsToNull Middleware

– “Real-Time” Facades

– Custom Pivot Table Models

– JSON Based Language Files (more info)

– Object Based Eloquent Events

– Job Level Retry & Timeout

Full changelog here.

Video Summary of New Features:

For a quick overview of all the features, check the youtube video from Laravel News.

Laracasts Series “What’s New in Laravel 5.4”:

Although, if you want a more in-depth explanation of the main new features, Jeffery Way series on Laracasts is the best place to start.

Laravel Podcast

If you’re also the kind that also likes to know the thought behind every new feature, the podcast is the best place to go. In episode 51 of Laravel Podcast, Taylor Otwell talks about the reason behind some of this improvements.

Upgrading to 5.4

If you’re looking to upgrade your project from 5.3 (or bellow), follow the official upgrade guide. The Laravel documentation is, in my opinion, one of the more complete and easy to read in all the frameworks I have used, and their upgrading guide is no exception. The estimated time from the 5.3 to 5.4 is around 2 hours.

Sources:

https://laravel-news.com/laravel-5-4

https://laravel.com/docs/5.4/releases#laravel-5.4