In the beginning of this year, we wrote about the release of Laravel 5.4 and all the new features, which came with it. Yesterday marked the release of, by his own admission, Laravel creator’s favorite version – Laravel 5.5:
Leave tomorrow for @LaraconEU. 5.5 next week also. Favorite release yet. Love the shape the framework is in. Never been happier with it. 😍
— Taylor Otwell (@taylorotwell) August 25, 2017
This is the next major release since 5.1 and it will receive bug fixes for the next two years and security fixes for the next three. The new version requires PHP 7+, which in itself is sure to decrease CPU consumption and speed up performance up to twice. Make sure you use PHP 7 on your hosting account before installing the new version or upgrading. If you are already using Laravel 5.4, upgrading to 5.5 should be easy as you are already using PHP 7. So…
What is new in Laravel 5.5?
This new simple interface will help you structure big controller files by converting objects returned from controllers with actions or routes with closures into HTTP responses. This happens by implementing a
toResponse() method. Before sending the response, the route class checks for this method and sends it accordingly. This also allows you to provide a layer with additional functionality by adding transitional code to the response. You can check the commit on GitHub and read detailed examples from the Laravel post.
Dump and “Dump and die” Methods in Collections
That new feature will make debugging faster and easier. Instead of assigning a variable to a particular connection and then dumping it whenever changing the collection, now you can now call both methods on a collection directly. When you debug a collection and want to check each transformation in the chain, you can set
dump() to output the result and continue the process or
dd() to dump and stop the whole process.
You can start using these methods thanks to Collection Macros – a 3rd party package, developed by the Belgian agency Spatie.
Data Return from the Validator
On Laravel 5.5 you can create an object directly from the validated data. You have to make sure to define all the fields as otherwise any attribute not it the validate method will not have a value. To be sure, simply pass the object with all its attributes through the validation method even if they do not require validation. You can see examples on the Laravel website.
You can now exclude repetitive checks from your blade templates to optimize structure and readability. This is done through the via the boot method in the AppServiceProvider class. You also have the option to make your checks more dynamic by passing arguments with
Blade::if(). For more information, watch the official Laracast tutorial.
Mailables rendering and themes
On Laravel 5.5 you can display HTML emails in the browser directly from a route. The Mailable class now implements a
render() method from the Renderable contract. This will help you see what your emails look like before actually sending them and edit the browser view right away.
Laravel 5.5 comes with another update in the Mailable class – selecting which email theme to use. You could design your own branded theme for emails in Laravel 5.4, but now you can easily deploy it as well.
Front End Presets
Previous Laravel versions had Bootstrap and Vue installed by default to help with the front end. Now, if you do not want to use them, you can remove those front end interfaces with command
php artisan preset none. Also now you can use the React Preset by typing command
php artisan preset react. You can see details and examples in the official Laravel post.
Until now, Laravel had only the option to rebuild the database by rolling back and rerunning all your migrations via command
migrate:refresh. Laravel 5.5 introduces command
migrate:fresh which drops all the tables, then runs the existing migrations again.
What has changed in Laravel 5.5?
Whoops is back!
Whoops is a PHP error handles, which used to come with Laravel 4, but was removed on 5. Now, Whoops is back in the picture to make debugging much easier. Every time there is an error, Whoops displays the line of code, which caused it as a screenshot, together with the error message.
Provider Prompt for
In Laravel 5.5 running command vendor:publish without a flag will require you to choose a provider so that you only publish what you want. To avoid this prompt, you can use either the
Custom Exceptions report method
The handling of exceptions in older Laravel versions was made by writing a code in the report method of the App\Exceptions\Handler class. However, in the event of multiple exceptions, this could make your application messy and hard to read. In the newest version, you can create a
report() method inside the exception itself, specifying how it should be handled.
Other improvements in the new LTS Laravel version include better design of the error pages, easier creating and updating of pivot models, custom validator rules, and more. For a full list and descriptions of the new stuff in Laravel 5.5, visit their news website. You can also check out the video introducing the new features:
The new Laravel 5.5 is fully supported on all WebHostFace packages. For more information about our services, contact us via our 24/7 live chat!