Laravel 5.5 is here! What’s New?

The wait is finally over! Version 5.5 of Laravel is now officially out and as expected the Laravel community is super excited about the new features of the new version. As this is a major release, it is jam-packed with goodies and continues the improvements made in Laravel 5.4 by adding package auto-detection, API resources / transformations, auto-registration of console commands, queued job chaining, queued job rate limiting, time based job attempts, renderable mailables, renderable and reportable exceptions, more consistent exception handling, database testing improvements, simpler custom validation rules, React front-end presets, Route::view and Route::redirect methods, “locks” for the Memcached and Redis cache drivers, on-demand notifications, headless Chrome support in Dusk, convenient Blade shortcuts, improved trusted proxy support, and many more.

In addition, Laravel 5.5 corresponds with the release of Laravel Horizon, the beautiful new queue dashboard and configuration system for your Redis based Laravel queues we have already shed some light on.

Without further ado, let’s see what this new version has to offer.

Frontend Presets

Since Laravel 5.3, the framework has shipped with optional Bootstrap and Vue.js scaffolding to help us with the front-end bit. Although you could remove them and start over with your personal preferences, the suggestion was only limited to the Vue.js framework.

While the basic Vue scaffolding is still included in version 5.5, several new frontend preset options are now available. In Laravel 5.5 a new Artisan preset command has been added that allows you to replace out the default with other tools like React, Bootstrap only, and even removing all of it.

Custom Blade::if() Directives

Blade is the simple, yet powerful templating engine provided with Laravel. Long repetitive checks within blade templates can make our templates ugly though. You can now exclude repetitive checks from your blade templates to optimize structure and readability.

Laravel 5.5 Blade::if makes it more convenient to abstract repetitive checks out of blade templates, leaving our templates looking cleaner and more readable.

The good news is that it’s now possible to abstract repetitive checks out of templates, leaving our templates looking cleaner and more readable.

Automatic Package auto-detection

Up until now, in order to use a third party package in our Laravel projects you had to follow these steps:

  • Install the package
  • Register the package’s service provider
  • Register facades if any

While Laravel packages aren’t usually hard to install, it could be simpler. Luckily, now it is. Package developers will now be able to add a new section to their composer.json files that inform the framework of any service providers or facade aliases that should be registered.

You can simply require the package:

composer require barryvdh/laravel-debugbar:dev-master

And the package’s service provider will automatically be registered and enabled. You can also disable auto-discovery for specific packages.

Auto-registration of Artisan commands

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. Instead, a new load method is called from the commands method of your kernel, which will scan the given directory for any console commands and register them automatically:

/**
 * Register the commands for the application.
 *
 * @return void
 */
protected function commands()
{
 $this->load(__DIR__.'/Commands');

// ...
}

PHP 7 now a Pre-Req

Laravel has always been a framework that isn’t afraid to push forward. As with Symfony 4, version 5.5 requires PHP 7.0 at the minimum. The support for PHP 5.5 has already ended and the security support for 5.6 is going to end in 2018.

Along with developer features, PHP 7 includes speed improvements which will drop latency by half and will decrease CPU load on the servers by at least 50%. So, you should definitely make this upgrade. And if you are using Laravel 5.5, making this upgrade will be a relatively painless process since it already runs on the latest PHP version.

The Next LTS (Long Term Support) Release

For those not familiar with LTS, these are special versions that are feature locked at the date of release. They do not get any new features but keep getting bug fixes and security updates throughout the maintenance window. Version 5.1 was Laravel’s first LTS release and its two-year window of bug fixes are coming to an end this year.

Laravel 5.5 will be the next LTS (Long Term Support) release after Laravel 5.1. Just as the previous LTS this will include two years of bug fixes and three years of security updates.

Whoops is Back!

Laravel 5.5 has brought the Whoops package back, changing the way errors are displayed. With Whoops, every time we have an error in development, we’ll be able to see the line of code that resulted in the error in the form of a screenshot as well as the error message.

Whoops, PHP error-handling framework, which came pre-installed in Laravel 4, was later removed with the release of Laravel 5.0. But with Laravel 5.5, it’s coming back pre-installed.

Some of the features of Whoops includes:

  • Flexible, stack-based error handling
  • Stand-alone library with (currently) no required dependencies
  • Simple API for dealing with exceptions, trace frames & their data
  • Includes a pretty rad error page for your web app projects
  • Includes the ability to open referenced files directly in your editor and IDE
  • Includes handlers for different response formats (JSON, XML, SOAP)
  • Easy to extend and integrate with existing libraries
  • Clean, well-structured & tested code-base

What Whoops actually does is that it makes the annoying PHP errors and exceptions a little less annoying by changing how they appear. With Whoops, every time we have an error in development, we’ll be able to see the line of code that resulted in the error in the form of a screenshot as well as the error message. As you can see in the image that it sports the lines of the file in which the error or exception occurred and traces back the operation till inception. And not forgetting to mention, it has zero dependencies (currently(‘pre-laravel-55’)).

“vendor:publish” Gets a Provider Prompt

In previous versions of Laravel, running the vendor:publish command will publish everything it finds, which includes configs, views, migrations, and other resources of all vendors. But in Laravel 5.5, running this command without any flags will prompt you to select a provider or tag, making it easier to publish only the ones you want.

The prompt can be bypassed by using either the --all or --provider flag with the publish` command. This means you can still use it in automated deployments and in your package instructions.

Source: https://laravel-news.com

Support for Email Themes in Mailable

In Laravel version 5.4, we were introduced to Markdown emails, but there was no option for customization. In Laravel 5.4, you can achieve this by creating your own theme.

However, some people still prefer having some custom styling in their email templates for branding purposes. In Laravel 5.5 you can achieve this by creating your own theme.  To use a custom theme for a particular Mailable, start by generating a CSS file containing your custom styling at the following path:

touch resources/views/vendor/mail/html/themes/custom.css

Now, simply specify this filename as a property in the Mailable class:

class SendInvoice extends Mailable
{
protected $theme = 'batman';
...
}

This way, the email layout will be based on the styles we defined in the custom.css file. The great thing about this approach is that you can have different themes for different Mailables.

Rendering Mailables to the Browser

When you are building custom HTML email templates, it’s tedious to test them across all the email clients, and testing them over and over. There are other tools like Litmus which solve this problem, but the service is pretty expensive relative to this tediously trivial task. Another way to test them while you are developing is to render out the email to the browser so you can make instant changes. But it is not an easy task.

Luckily, that is changing in Laravel 5.5 as it adds the facility to display them directly from your routes. Mailables can now be returned directly from routes, allowing you to quickly preview your mailable’s designs in the browser:

Route::get('/mailable', function () {
$invoice = App\Invoice::find(1);

return new App\Mail\InvoicePaid($invoice);
});

Introducing the migrate:fresh Command

You’ve probably found yourself in a situation that required you to rebuild the database during development. With the former Laravel versions, we achieved this by running the php artisan migrate:refresh command which rolls back migrations and then reruns them.

Coming to Laravel 5.5 is an improvement on this with a new “migrate:fresh” migration command which is a nice addition to creating a clean database in development. The migrate:fresh command drops all the database tables and then runs the existing migrations again. The difference between “refresh” and “fresh” is that the new fresh command drops all the down methods or the rollback by dropping the tables, then running through the up methods.

Error Pages: Design Improvement

In Laravel 5.5, a new and improved design change is made for the error pages like 404 or 50* errors.

The default errors will extend from an errors::layout file and get some small design additions over the current style with flexbox and a vertically centered message.

Request Data From Validation

A new feature coming to Laravel 5.5 is the Validation which will now return the request data after validation. Now you can directly save the data after validation.

Custom Validator Rules

Laravel 5.5 is coming with a new feature for adding custom validation rules. Custom validation rules are nothing new but with Laravel 5.5 you can have a dedicated class to handle the validation. To define a custom validation rule, you need to create a class with two methods: passes and message. You can place this class anywhere like in the App\Rules namespace. The passes method accepts two arguments: attribute and value, which you can use to validate the field.

In addition to the above-mentioned features, Laravel 5.5 comes with a host of awesome features that could make the lives of Laravel developers a lot easier. Check out the official announcement for more details.

Installing Laravel 5.5

As you can see a lot of cool and exciting stuff is coming along with the new release.

Laravel 5.5 is currently not available in Softaculous for install, but you can still install it manually via Composer using the following command in your /home/user/.composer directory:

composer global require "laravel/installer"

To create a new instance of laravel, you will have to go to your public_html and type:

composer create-project --prefer-dist laravel/laravel blog

Where blog is the name of the folder which will be created and in which Laravel will be installed. Now access the folder and execute:

find . -type d -print0 | xargs -0 chmod 0755 && find . -type f -print0 | xargs -0 chmod 0644

This will change the permissions to the desired ones which will allow the /public folder to be displayed correctly and you will be able to open the website on your browser.

Upgrading from 5.4 to 5.5.0

As mentioned above, Laravel 5.5 requires PHP 7.0.0 or higher so before proceeding with the upgrade, check whether the needed version is set up.

Log into cPanel and navigate to the File Manager. Move to the directory you have chosen for Laravel and find the composer.json file. Select all of the lines in it and replace them with the following ones. Alternatively, you can do all of this via a command prompt by utilising vim. Once you are ready, you will need to update the composer using this command:

composer update

Note that this will upgrade Laravel and all of its packages to the latest version as well as add the ones missing, instead of just upgrade the version of the Laravel core to 5.5.x.

If you want to be sure the version has been upgraded, you can use:

php artisan --version

This will show you that the latest version is now available.

Furthermore you can check if the different new packages are working but that has to be done one at a time. For example, in order to test the Whoops package, simply make a mistake in the code of your published page and the refresh that same page in your browser. Whoops will come up and provide you with the exact information on what has gone wrong in loading the page. Due note, that this can be done only with an active .env file. As a default, the installation comes with a .env.example file which will not activate Whoops.

Conclusion

As you can see, we have a lot of exciting new stuff. And the best of all is that the new Laravel 5.5 is fully supported on all FastComet plans. Hope you all enjoy the changes that were made in Laravel 5.5 release and Happy Coding!

Elena

Elena oversees all Marketing, Product Management and Community efforts for FastComet and is in charge of telling the brand's story. Always pitching, she’ll share the FastComet vision with anyone who’ll listen. Elena helps our customers make the most of their web sites' and focuses on our inbound marketing efforts; everything from developing new online growth strategies, content creation, technical SEO, and outreach within the FastComet community. Her background includes Sales and Customer Relationship development, as well as Online Marketing.