A small, but long-requested addition, you may now send a
validate message directly on your
Request instance. Even better, this method call will return the validated data, which means you can pass the result directly to your model's
update methods. Simpler code for the win!
migrate:fresh Artisan command is being introduced as part of Laravel 5.5. This is similar to the existing
refresh option, however, rather than rolling back all of your migrations (and triggering the respective
down method for each), this new command will simply drop all tables and run your migrations from scratch.
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!
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.
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!
In Laravel 5.5, you'll find a brand new
App/Rules folder. The next time you require custom logic for a particular request attribute, you'll laugh at how simple it now is.
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:
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.
In Laravel 5.5, you'll find a sweet new syntax for defining custom
if Blade directives. Want a useful
@subscriber directive 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.
Though Mix is entirely separate from Laravel 5.5, you will find a bump to version 1.0 in your
package.json file. In this video, we'll review a few new additions, including updated versioning, sequential custom tasks, fast Sass compilation, CSS purification, and more.
In Laravel 5.5, you'll no longer be required to manually register your Artisan commands. The framework will instead automatically scan the
commands folder for you. The means you may now run
php artisan make:command FooCommand, and then immediately trigger it. Useful!
tap() 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.
Please note that this update to
tap() is also available in fresh 5.4 installs.
In previous versions of Laravel, you were presented with two database-specific traits for your test classes:
DatabaseMigrations. 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 single
RefreshDatabase trait that automatically figures out which DB reset strategy to use.
Laravel offers two new useful Blade directives as part of version 5.5:
@guest. They do exactly what you'd imagine, so say goodbye to the constant
You may now use the helpful
Route::redirect() helpers within your
routes.php file. Think of these as shorthand for loading a view and performing a redirect, respectively.
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.
When an exception is thrown in your app, you can optionally let it bubble up to
app/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.
A more object-oriented approach would be to allow the exception to determine how to render itself. And now, in Laravel 5.5, you can do that very thing.
Laravel 5.5 includes a new
helper() 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 returns
null? Well now we have a cleaner way to do this.
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 the
toArray() 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.
*Series still in development. Check back often for updates.