Laravel 5.3 was announced at Laracon 2016, showing off several what is new in Laravel 5.3, and features that it includes. This version of Laravel actually includes a large set of new features, a large enough set in fact, that for many frameworks this might constitute a major release.

For Laravel though, we simply move up from 5.2 to 5.3, but I am excited to show everyone all of the exciting new features that are in Laravel 5.3. We will start with the basic stuff, the small things in this blog post, and then move towards more detailed features as we progress.

Laravel 5.3 is a large update of open source packages.

– Taylor Otwell

This series will be spread across many posts, so be sure to reference the top of each post to get to what you are looking for.

PHP 5.6

Starting in Laravel 5.3, Laravel will be requiring php version 5.6 to run. No this is not very exciting, but it is definitely something you should be aware of. For me personally, I am running on a Mac which still uses PHP v5.5 as the system PHP. This meant that Laravel would install but couldn’t run. Many of the dependency versions Laravel 5.3 uses now require a minimum PHP version of 5.6, so composer would fail when it tries to install or update dependencies.

Not sure which version of PHP you have? In your terminal you can simply type:

php --version

This will output your version and just make sure you are at 5.6 or higher. If not, you need to start looking at installing a newer version of PHP. I would recommend using Homebrew if you are on Mac, as this will allow you to install PHP7 easily and it won’t conflict with your system level PHP for your mac.

Multiple Migration Paths

One of the feature types you will notice in Laravel 5.3 is that Taylor Otwell actually added lots of small features to make life easier for package developers. This is a good move because it encourages package development which is the cornerstone for any successful framework. The reason Ruby on Rails took off in the fashion that it did, was becuase its Gems package manager because hugely popular, so gems were available for anything, making projects faster and easier to develop.

One of these such features is the ability to load migrations from several folders (not just the migrations folder). This allows package developers to load migrations from their vendor files, instead of requiring us to copy migrations into our migrations folder now, developers can tell Laravel about another migrations directory. This means that we can just run php artisan migrate and Laravel will now check all of its known migration directories for new migrations to run. Easy on package developers!

To associate a new migration directory:


Migration Step-based Rollback

Can I just take a moment to say how grateful I am for this little feature? It has actually bothered me for a long time that this didn’t exist in Laravel yet. I am talking about rolling back migrations.

In the past, we had only a few options for rolling back migrations. We could roll back the last migration, or we could roll back ALL of the migrations. This was annoying, because sometimes you wanted to rollback the last 2-3 migrations but not all of them. Until now, this wasn’t an option, but thank you Laravel 5.3 because it is finally here!

php artisan migrate:rollback --step=3

Now this will rollback the last three migration steps. Keep in mind that if you run multiple migrations at once, they will count as one step, so reversing that step will reverse potentially multiple migrations. This is why I like to run one migration at a time, or two max if they are related (like users and password_resets on a new Laravel install).

Elixir 6 Released

Elixir is the task manager built for Laravel, on top of Gulp. In fact it runs in a gulpfile.js and makes many gulp tasks easier to run. Shortcuts such as .sass() will compile your sass without any complex setup. This makes working with a task manager easier and faster than ever before.

With Laravel 5.3, comes the release of Elixir 6 bundled in. The main improvements with Elixir 6 is support for Webpack.js and Rollup.js as a module bundlers. In addition, the user interface and user output of Elixir has been greatly improved.

Elixer 6 layout for Laravel 5.3
This is the new layout of Elixir 6. It makes it super easy to see what is happening.

This is a nice addition to a growing framework. We will be doing future tutorials on Elixir and these module bundlers.

New Layouts

Another small change, and potentially insignificant, but it is worth noting that you will find new layouts as your default views in Laravel 5.3. The default homepage when you build a new Laravel app (the welcome.blade.php file) now includes a list of sublinks that link to Laravel’s Twitter, Github, and Documentation. You will delete these files right away when building a new app, but it is worth noting the change.

New in Laravel 5.3 Login Page

When you run php artisan make:auth the new views generated are also cleaner. Taylor mentions that he pulled them from Laravel Spark. So they look clean and crisp. Overall, I was impressed when I saw the default login and register views for the first time. You could honestly use them in a production app with no changes if you wanted to.

Dependencies Pulled from Package.json

As minor as it might be, it is worth noting that dependencies like Vue.js (more on this later), jQuery, and Bootstrap are no longer pulled in from your template files, but instead through your package.json file. As you can see here, all of our dependencies are located by default in this package.json file located in your application root.

These dependencies are pulled in through NPM, and then extracted to assets/js/bootstrap.js where you can set these things up and load them into your views or template files.

laravel 5.3 package.json file

If you wanted to get rid of Bootstrap or Vue.js or jQuery for that matter, you will want to seek out this file to eliminate them. Hopefully this saves you a lot of soul searching while trying to figure out where they are coming from.

Oh, don’t forget to run Gulp. 😀

Controller Changes

I know, I know… you saw this title and you spit out your coffee. You are covered in deep sweat and your labored breathing is about to hit panic-attack mode. Before you hit any higher level of freak-out-ed-ness, these are all small, non-breaking changes for the better.

Ok with that out of the way, what changed in Laravel 5.3 for controllers? As I mentioned above, they are all non-breaking changes, meaning you can continue to do whatever you did before and Laravel won’t care.

If you are writing packages for Laravel and are creating a controller that doesn’t require all of Illuminate routing features, then you can now omit the extends controller on your function. You can generate data right inside the controller for use in your package without all of that overhead. Nice little change. 😀

This will not effect most of us because most of our Controllers need Illuminate\Routing so you will still need to extend controller for most of our general use controllers.

Controllers also can have a new __invoke() method for controllers that only have one method. Sometimes when writing complex controller methods you might find it easier to extract an overly complex method to its own controller. Now you can put that method into the __invoke() method and call that controller from a routes file with just the controller and not the @ sign afterwards. Calling just your controller and no method will initiate the __invoke() method. Cool stuff!

Inline Custom Artisan Commands

Need to build a quick artisan command? Well now in Laravel 5.3 it is easier than ever before. You can now build custom artisan commands (these are the php artisan ____ commands that we use in the terminal) right inline in our Kernel.php file.

The command will pull in any parameters you pass it in the terminal and you can define what you want it to do right from within a closure.

An example of a quick command would be like this:

protected function commands()
    $this->command('im {name}', function($name) {
        $this->info('Good to meet you '.$name);

This will now output in the terminal like this.

Terminal artisan commands

These commands will also show up in your Artisan help file. So you can run php artisan help and you will see our new “im” command. If you want to write a better description for this command you can also append ->describe('Human readable text here'); to your closure as well.

Artisan closure

With this describe command now in place, we can run php artisan list and see in our help file now, in alphabetical order is our im command (we really should have given this a better name).

artisan list command with description

Running Queue Workers

If you are running any queue workers, then the good news is that a lot has changed under the hood of Laravel to make working with Queue workers so much better. Queue workers felt like a beta feature in Laravel 5, so Taylor Otwell now says that the entire underlying framework for Queue workers has been overhauled. This will make them more reliable in general, but there are two minor API changes that you might want to know about.

First is that now when you run php artisan queue:work it will by default run the ongoing daemon. This is equivalent to the old command php artisan queue:work --daemon, so you no longer need to run that command. Just run the base command to get the daemon (which is what you usually want anyway. If you do in fact want to run the queue workers only one time, then you can pass in the flag --once in the same way you passed the daemon flag before. This will run it just one time. In my opinion this was a good change, because I feel like the daemon was a more common use of the queue workers anyway so you might as well make it the default.

Furthermore, if you have ever had a queue worker get stuck, preventing jobs from running then you will jump for joy with the new timeout command. In your queue worker command now you can issue a time (in seconds) that you want the queue workers just give up and continue working on the next job. You will get a log entry for the error.

The really nice thing about killing queue workers is that the jobs can continue to run. So you are freeing the worker up to do more jobs, but the jobs can continue to finish in the background.

FirstOrCreate() Accepts Custom Parameters

There isn’t much to say with this one other than you can do it and it will be nice. 😀

Basically when calling firstOrCreate() you can now pass in other parameters to save to the new user if you end up needing to create it.

User::firstOrCreate(['github_id', $githubUser->id], ['avatar' => $githubUser->avatar]);

You can read the pull request here, and as you see, I pulled this example straight from the pull request. In this example we see that we let a user login with oAuth via GitHub. We don’t know if this is a new user or not, so we find a user by this github_id and if they exist then we grab them, if they do not exist, then we create a new user with this github_id and also pass in their github avatar while creating the user. Slick!

Query Builder Now Returns Collection

Most of the stuff you read on here are awesome new features to have, but we didn’ really notice they were missing until now. But the feature I want to discuss now is something that really should have been this way for a while. So I am eternally grateful that we finally have this change.

If you didn’t know already, when you decide to use Eloquent to get a resource (like User::all() or User:find($id) then you get an Eloquent collection object returned to you. This means you can do things like $user->id or $user->email. But when you use the query builder you aren’t as fortunate (until now). In the past versions of Laravel, we would get an array returned by default from the query builder. This was annoying because you would sometimes get collections and sometimes get arrays depending on how you got your data. Now all of your commands will return collections, regardless of whether it is a Eloquent command or a Query Builder.

What Is New in Laravel 5.3?

Visit back frequently to see updates. Videos coming out soon for all of these new features.
  1. All the Small Changes (There are a lot) in Laravel 5.3
  2. Directory (file) changes in Laravel 5.3
  3. Changes to Routing in Laravel 5.3
  4. NPM and Yarn in Laravel 5.3
  5. Cache global helper in Laravel 5.3
  6. Custom Pagination in Laravel 5.3
  7. Pivot table toggling instead of sync in Laravel 5.3
  8. Image dimension validation rules in Laravel 5.3
  9. Working with JSON and MySQL in Laravel 5.3
  10. Easier file uploads in Laravel 5.3
  11. Easier Mail() with Mailable in Laravel 5.3
  12. Notifications with Notifiable in Laravel 5.3
  13. Easier Searching with Laravel Scout in Laravel 5.3
  14. Easier Broadcasting with Laravel Echo in Laravel 5.3