Take on the Laravel 6.0 latest features

One of the most popular PHP frameworks, Laravel turned 8 this year, and the older it gets, the more likable it gets. Not to say we didn’t like it before! Another exciting thing that has happened this year is the release of Laravel 6; the latest major release has brought with some it very new amazing features, improvements and corrections. In this article, we’ll quickly go through all the most important changes that came with this major release. 

Before we do that let’s first take a look at what’s LTS.

Laravel 6.0 Is the New LTS (Long Term Support)

Ok, let me break it down for you, there are two kinds of releases; LTS releases & general releases (non-LTS). Bug fixes are provided for six months and security fixes for one year for the general one, while the LTS one gets bug fixes for two years, with security fixes being provided for three years. As easily evident, LTS releases offer the most extended period of support and maintenance. 

6.0 is the new LTS version of Laravel which will get bug fixes until September 3rd, 2021 and security fixes until September 3rd, 2022. Laravel 5.5 was the previous LTS (with security fixes until August 30th, 2020).

Semantic Versioning

Like other 1st-party Laravel packages, the Laravel framework package is too officially adopting the more traditional semantic versioning. Thus making the two consistent with each other. The current six months Laravel release cycle will remain unchanged. 

Laravel Vapor Compatibility

The latest release includes the launch of a much-anticipated product, Laravel Vapor, it is an “auto-calling, serverless deployment platform (a method of providing backend services on an as-used basis) for Laravel.” 

Previously, Laravel Forge was mostly utilized to provision and deploy apps. With it, you could connect your chosen server and Forge would provision it specifically for your Laravel application. This is all great, but you still had to manage updates on your own. Vapor not only do this but does even more. As mentioned above, Vapor is completely serverless meaning you wouldn’t be required to manage and update servers for your Laravel application.

Let me make it clear serverless does not mean servers are not involved, it just means you don’t have to deal with them. Another benefit is that you’ll be charged based on usage, not a fixed amount of bandwidth or number of servers. This also means you don’t have to worry about scaling, as it will automatically be done for you.

Let’s cast a look at some more awesome features that Vapor provides:

  • Powered by AWS
  • Zero downtime during deployment
  • Extremely fast
  • Create and scale your databases from Vapor
  • Backup and restore databases
  • Metrics and monitoring with notifications
  • Purchase domains and manage DNS from Vapor dashboard
  • Automatically added SSL certificates
  • And the list goes on.

Job Middleware

Job middleware allows for wrapping custom logic around the execution of queued jobs, reducing boilerplate in the jobs themselves. Small time savings for a developer who uses jobs extensively.

Improved Authorization Responses

Previously, it was very difficult to acquire and expose the custom authorization messages to the end-users. Making it hard to explain to end-users why a certain request has been denied. But with this latest release, it can be easily achieved using the authorization response messages and the new Gate::inspect method.

Lazy Collections

Laravel’s Collection class comes with a number of useful methods. The latest addition to this list, Lazy Collections leverages PHP generators, allowing you to work with extensive datasets while helping you look after your server’s memory better. 

Let’s say your application has to process a multi-gigabyte log file while taking advantage of Laravel’s collection methods to parse the logs. Instead of reading the whole file into memory at once, lazy collections can be used for keeping only a certain small part of the file in memory at a given time.

Or, for instance you need to iterate through ten thousand Eloquent models. When using traditional Laravel collections, all ten thousand Eloquent models must be loaded into the memory simultaneously, which is not a good thing. Now, you can use a cursor method instead of all(), which returns a LazyCollection. This allows you to run a single query against the database and at the same time only keep a single Eloquent model at a time, loaded in memory.

Eloquent Subquery Enhancements

Eloquent has always made it easier to run complex queries. Laravel 6.0 gives you even more help when it comes to running subqueries, or a query within a query, in a single call. This can come-in handy when you need to select information from two tables with a relationship. For e.g., you have a table of flight destinations and a table of flights to destinations. The former has an arrived_at column that indicates the flight’s arrival at its destination. 

Using the new subquery select functionality in the latest release, you can select all of the destinations and the name of the flight that most recently arrived at that destination using a single query, which should eliminate a lot of that pain!

Also, you can use new subquery features added to the query builder’s orderBy function to sort all destinations based on when the last flight arrived at that destination. Again, it can all be done while executing a single query against the db.

Laravel UI

One other update you should know about is the extraction of the laravel/ui package. Although, not included by default, front-end scaffolding will still exist. Meaning you won’t see any Vue or Bootstrap scaffolding in a new Laravel 6.0 application. To restore the traditional Vue/Bootstrap scaffolding that is present in earlier releases, you should install the laravel/ui package and use the ui Artisan command to install the frontend scaffolding.

Ignition – the New Error Page for Laravel

And last but certainly not least, the latest release comes with Ignition, a new open source exception detail page created by Freek Van der Herten and Marcel Pociot. The default error page for the latest release offers many advantages over earlier releases, such as improved Blade error file and line number handling, runnable solutions for common problems, exception sharing, an improved UX and so forth. One might even enjoy throwing an exception on purpose to see this beautiful new debugging stack for Laravel.

Bottom Line

As you can see for yourself, the latest release is as good as it can be. The list does not end here, I can go on and on, these were just some of the most important features that came with the new release. If you’re not using this version yet I do hope you are now considering an upgrade. Laravel 5.8 will be supported for another year. If you’re using 5.7 or older (with the exception of Laravel 5.5 of course), keep in mind that the support has already expired and no further security fixes will be released.

Leave a Comment

The reCAPTCHA verification period has expired. Please reload the page.