What’s New in Laravel 5.3 Release

Introduction

As we all know we’re getting more closer to Laravel 5.3 release and expecting some cool features. So today I thought I should write my own perspective on this release. There are lots of changes including some big changes and some small changes we’re expecting to see in this release. Also there are also some cool new features that are coming out of the box. So lets begin with pointing out list of features and modification we’ll see.

New features & Modifications

1. The App Folder

Yes, you heard right. The one of the major changes in Laravel 5.3 is the change in app directory. So now you wont see things like Events,Jobs, Listeners and Policies directory out of the box. They’re excluded by default but not removed. Its like if you need them you can bring them back using artisan commands which we generally use to create policies, events or jobs.
Example
php artisan make:policy PolicyName
php artisan make:event EventName
php artisan make:job
Running those commands will bring back the respective directory automatically but if you don’t need one of these things, you don’t have to keep these files by default as we used to do in previous versions.

2. Laravel Echo

Laravel echo is one of the coolest feature in laravel 5.3. So what’s Laravel Echo? It’s a tool that makes it easy for you to bring the power of WebSockets to your Laravel applications. Laravel has its awesome event broadcasting and listening feature you might have used before in previous versions but Laravel Echo is just the thing you wanted if you’re more into WebSockets and realtime application or messaging system. I would love to share Matt Stauffer‘s blog post Introducing Laravel Echo: An In-Depth Walk-Through in which he had explained each and every bit of laravel echo and how you’d use in your laravel powered application.

3. Migrations

As we already know that Laravel’s migration is awesome feature to fuel rapid development process. So in version 5.3 they’ve added a little but useful feature while rollbacking migrations. In previous versions rollback was a bit tricky as its lets you roll back only the last migration but, now you’ll see there is one flag called step added so that you can roll back to multiple steps or migrations.
Example

php artisan migrate:rollback --step=2

4. New Function in Blade @foreach loop

This new release introduces a $loop variable inside a foreach loop. This variable provides a couple of properties that can help us easy manage indexes, increments in loops etc. Now in Laravel 5.3, we can do stuff like.

@foreach ($countries as $country)

    @if ($loop->count)
        @if ($loop->first)
            <li class="list-item list-item--header">{{ $country->name }}</li>
        @elseif ($loop->last)
            <li class="list-item list-item--footer">{{ $country->name }}</li>
        @else
            <li class="list-item">{{ $country->name }}</li>
        @endif
    @endif

@endforeach

5. Query Builder Returns a Collection

Oh yeah, I assume you have already got what I am about to write. Laravel Collection is the coolest feature so far, just like underscore.js and gives all the needful functions out of the box. Now from laravel 5.3 they’ve added one more feature which will make your development faster and code cleaner because you don’t have to collect data to use laravel collections. The query builder will return collection now.

//Previously we had to do like this
$posts = Post::all();
if (collect($posts)->isEmpty())

//Now you can achieve this simply by eloquent model
if(Post::all()->isEmpty);

There are still lots of surprises which is yet to come in this release. I’ll add more in this list and try to keep you guys updated.