What's New in Laravel 5.5
Here we go again! Currently scheduled for an August release date, we're on the verge of Laravel 5.5. With that in mind, let's get a head start on the new features and additions to the framework. As always, there's quite a few!
Progress
Series Info
- Episodes
- 20
- Run Time
- 1h 31m
- Difficulty
- Intermediate
- Last Updated
- Aug 30, 2017
- Version
- Latest
Series Episodes
- Episodes (20)
Laravel 5.5 Installation and Whoops
Let's get started by installing, at the time of this recording, the development version of Laravel. That way, we can pull in the 5.5 version of the framework. Once setup, we'll also take a quick look at the new Whoops integration.Streamlined Request Validation
A small, but long-requested addition, you may now send avalidatemessage directly on yourRequestinstance. Even better, this method call will return the validated data, which means you can pass the result directly to your model'screateorupdatemethods. Simpler code for the win!Fresh Migrations
A newmigrate:freshArtisan command is being introduced as part of Laravel 5.5. This is similar to the existingrefreshoption, however, rather than rolling back all of your migrations (and triggering the respectivedownmethod for each), this new command will simply drop all tables and run your migrations from scratch.Frontend Presets
Out of the box, Laravel ships with a small bit of frontend boilerplate to get you up and running as quickly as possible. Specifically, it includes a few Sass and Vue suggestions. However, as part of Laravel 5.5, you may now configure this initial boilerplate to your liking. Want to strip all of it? Now you can. Prefer to use React instead of Vue? Easy!Automatic Package Discovery
If you've ever installed a Laravel package before, you most certainly were required to visit your `config/app.php` file to add a service provider and alias. This is what allows the package to bootstrap itself into your Laravel installation. In Laravel 5.5, however, packages can optionally perform these steps automatically. In this video, we'll update an existing Laracasts package to allow for this very thing.Faster Email Layout Testing
Testing the layout of your mailables can always be a little tricky. Usually, we resort to sending the email to a test email server like Mailtrap, and then reviewing the output. In Laravel 5.5, however, we can now return a mailable class instance directly from any route. Convenient!Silky Smooth Custom Validation Rules
In Laravel 5.5, you'll find a brand newApp/Rulesfolder. The next time you require custom logic for a particular request attribute, you'll laugh at how simple it now is.Collection Dumping
Debugging a complex collection pipeline can get a little tricky. Often, you'll find yourself temporarily commenting out portions of code, as you confirm the dumped output. In Laravel 5.5, however, you'll find two new helper methods on your collection instances:dump()anddd().Model Factory Generation
In Laravel 5.4, all model factories were contained within a single file. Need to construct a new factory? Well, you know the drill: copy and paste the one before it, and make your changes. Luckily though, in 5.5, there's a simpler way. Each of your Eloquent models will now have a respective model factory file.Custom Blade "If" Directives
In Laravel 5.5, you'll find a sweet new syntax for defining customifBlade directives. Want a useful@subscriberdirective to conditionally load HTML for only the subscribers of your site? It's so easy! Give me a few moments, and I'll show you how.What's New in Laravel Mix
Though Mix is entirely separate from Laravel 5.5, you will find a bump to version 1.0 in yourpackage.jsonfile. In this video, we'll review a few new additions, including updated versioning, sequential custom tasks, fast Sass compilation, CSS purification, and more.Auto-Registering Artisan Commands
In Laravel 5.5, you'll no longer be required to manually register your Artisan commands. The framework will instead automatically scan thecommandsfolder for you. The means you may now runphp artisan make:command FooCommand, and then immediately trigger it. Useful!Higher Order Tap
Thetap()helper function has now been supercharged to be even more flexible. You may omit the closure second argument to this function, in which case a proxy class will be returned. This proxy will properly delegate to any method you call from that point forward, while returning your original value per usual. It sounds a bit confusing on paper, but you'll get a lot of use out of this one.The RefreshDatabase Trait
In previous versions of Laravel, you were presented with two database-specific traits for your test classes:DatabaseTransactionsandDatabaseMigrations. While it doesn't take too much work to understand the difference between the two, nonetheless, it could be confusing to newcomers. "Wait, which one am I supposed to use to reset my database? Which is better?" In Laravel 5.5, all of this has been streamlined (though these traits are still available for backward compatibility). You'll now find a singleRefreshDatabasetrait that automatically figures out which DB reset strategy to use.New Blade Directives
Laravel offers two new useful Blade directives as part of version 5.5:@authand@guest. They do exactly what you'd imagine, so say goodbye to the constant@if (auth()->check()).Route Helpers
You may now use the helpfulRoute::view()andRoute::redirect()helpers within yourroutes.phpfile. Think of these as shorthand for loading a view and performing a redirect, respectively.Toggle Exception Handling Within Your Tests
When writing tests for your application, you may encounter situations when you don't want Laravel to automatically catch and transform an exception. You can now disable exception handling on a test-by-test basis, via the$this->withoutExceptionHandling()method call.Cleaner Exception Rendering
When an exception is thrown in your app, you can optionally let it bubble up toapp/Exceptions/Handler.php. Here, you may type-check the exception to determine the appropriate response to return. While this is certainly useful, over the lifetime of a project, you'll notice that this method grows and grows.Optional Objects
Laravel 5.5 includes a newhelper()function, which you can think of as a generic null object implementation. Have you ever run into the situation where you need to fetch a property from a relationship, but it's possible that the relationship itself returnsnull? Well now we have a cleaner way to do this.API Resources
In Laravel 5.5, resource classes allow you to transform your Eloquent models into the proper JSON data structure. Though you can of course override thetoArray()method on your models to allow for this, when building an API that you intend to expose to potentially millions of users, it's important to codify this structure and response format as reliably and consistently as you can.
