Get the Scoop on Laravel 5.8
What a better way to start Thursday morning, having watched Laracon 2019 and all the great speakers attending the event delivered tremendously useful information for beginners and advanced users – we thought now would be the perfect time for us to share what Laravel 5.8 brings to the table, and oh boy it does look good.
Updates delivered as a Swiss Clockwork
Having an official release cycle known ahead of time is a pure godsend for us all. It gives us, the end users, the opportunity to plan ahead when we have to proceed with upgrades. Additionally, it provides the dev teams that use the software a way of knowing what is coming and when to expect it. After Laravel’s 5.X release, new updates have been delivered roughly six months one after another. This announcement and all new versions have followed this half-year schedule since 2015. Laravel always was on point with their schedule. Keep note that with the new 5.8 – now the older Laravel 5.7 will not get further bug fixes and updates. That was previously discussed when 5.7 was released. Still, 5.7 will get updates in regards to security until August 2019 which is some praiseworthy commitment by the core team. As of now, Laravel 5.8 is the most current stable version and will continue receiving the needed bug fixes and updates roughly until August 2019. All security fixes will be present approximately until February 2020. But we all know that having updates performed for the sake of updates alone isn’t enough.
While we perform compatibility tests on our platform to ensure our users are not going to have to face difficulties with the server environment itself, we do have the chance to play around with the scripts extensively either it being Laravel or something entirely different, we always look into the updates, as an end user would. Which bring us to the most important thing – what are updates, if they don’t bring
Meaningful changes in every direction
We all get excited when a software receives an update, and in our day and age, this happens on a daily bases. From our phones to the scripts we are using to build projects – updates are always welcomed, but having updates that polish and further improve the experience where it counts are the true hidden gems. Soo seeing changes to the
And its allowance for the use of international characters in email addresses is a small victory. This allowance will be possible if you have the validation code:
$request->validate([ 'email' => 'email', ]);
Previously, if you had an email address like exämple@yourdomäin.de, it surely would have failed due to the difference in the logic used by SwiftMailer, which is the PHP mailer library being used by Laravel. However, now with 5.8, it will pass validation flawlessly, as now both conform to RFC6530 compliance.
Wait, what is this and why do we use it? Carbon is the PHP library we are using for DateTime and Carbon makes our lives easier compared to the PHP built-in DateTime which at best can be a bit confusing. Carbon 2.0 brings new features with it, but that alone can be a topic on its own. So we will leave it for now without diving into too many details. Hopefully, we will discuss it in more details another time.
⏱Thanks to some hard work by Carbon maintainer Kyle (https://t.co/kLkpb3rVBm) you will be able to use Carbon 1.0 OR 2.0 in Laravel 5.8… This allows support for CarbonImmutable. You can even configure your application to always use CarbonImmutable. ⏱ pic.twitter.com/JpKAaoABo9
— Taylor Otwell ⚗️ (@taylorotwell) October 3, 2018
With that said, having the ability to choose from Carbon v1 or Carbon v2 for your DateTime functions is another welcomed addition to the changes that Laravel 5.8 brings to the table, and on top of that it also includes the ability not only to use Carbon immutable however even set it as the default.
We strongly recommend, if you want to know more about the migration from Carbon 1 to Carbon 2 and how it will affect you – to check out the official documentation.
The new release also brings support for the new dotenv 3.0 to manage your project .env file. One of its differentiating features is the support for more than one string and white space at their end in your environment file.
Previously, with the example above, it would’ve returned only specialstringfor. However, this won’t be the case anymore with the new update what you would get instead is specialstringfor thisapp which will be parsed. Another change that dotenv 3.0 brings is respect for spaces at the end of the string, which used to be stripped from the environment variables. This is useful especially in various use cases like for example when multiline API keys are needed for security. Things don’t stop improving here, and it gets even better due to the introduction of another now favorite feature:
Automatic policy discovery
In previous versions, whenever a policy class was generated, you had to visit your AuthServiceProvider and manually wire it up with the appropriate model. It’s undoubtedly wasn’t the end of the world, but it surely was a bit tedious process, to begin with. So seeing that the new release is changing that, and automatically discovers the new policy for you, as long as you follow the standard naming convention is a welcomed change.
Something that can easily be overlooked, if you don’t keep track of things or might have caught you by surprise is that
Array and String helper functions are deprecated!
Till now we used array_* and str_* global helpers, however, with the new release they were officially deprecated and should be removed in Laravel 5.9. If you were unaware of that change, don’t worry – there will inevitably be packages that can maintain functionality if you don’t want to rework your existing code, but as always, it is a good way for getting used to the new commands Arr:: and Str:: that should be used instead.
Cache TTL in Seconds, not Minutes
Cache time for Laravel will never be the same they say, and we agree. From now on the update cache time in TTL is changed from minutes into seconds. So basically, you have to remember this slight change and keep in mind the values you are entering are in seconds.
What else to expect?
- More flexibility regarding the parts of the environment we try reading and/or modifying;
- Highest level of support for multi-line variables;
- No further trimming of values, you now get them precisely as-is;
- Accept a catalogue of paths in order, to try looking for the dotenv file, instead of a single path;
- Stronger variable name validation in order to avoid silent failures or obscure errors.
We all understand the challenges that a new release brings with itself, and even if you spend countless of hours of testing and preparing things out in advance – there is no way to address all variables and other people use cases, so it comes to no surprise that Laravel received 3 quick fixes released since the end of February, 2019. You can see all the fixes and changes made in the official Laravel changelog, but for your convenience, I will outline a few below:
- Fixed environment variable parsing
- Fixed guessed policy names when using Gate::forUser
- Fixed via as string in the Notification
- Fixed StartSession middleware
- Fixed stack channel’s bug related to the level
- Fixed email validation for not string values
Installing Laravel 5.8
So you have decided to give the newest version a spin? You ain’t alone. We are all eager to try what working with the new release feels like, so after many tests bringing the latest version of Laravel 5.8.3 was a top priority. We have deployed Laravel 5.8.3 in Softaculous for new installs, however, as always you aren’t limited using only it. You can always install it manually should you prefer that using Composer.
Before proceeding with the installation – check whether the needed version of your hosting account is set up to PHP 7.3 if you have already done that you can skip the next paragraph.
On default with all of our hosting solutions, we have set the PHP version to be 7.2. Therefore, if needed you can quickly change it to 7.3 with a few clicks from your cPanel with us. In a previous post, we discussed in details what benefits using the newer PHP 7.3 but to keep it short here it is faster, more secure, and much more resource-efficient than older versions.
The manual installation should begin by 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 to Laravel 5.8 and beyond
If you are already using 5.7 and want to give the newest version a try, we strongly suggest creating a backup manually in advance even if we perform such on daily bases for you. If not feeling like doing that, you can always create a test environment before actually pushing the update for your live project. Just don’t forget that Laravel 5.8 requires PHP 7.3, so before proceeding with the upgrade, make sure the needed version is selected. We would also recommend to take some time and refer to the upgrade guide for 5.8.
If you enjoyed this article, then you’ll love FastComet’s Laravel SSD Cloud hosting platform. Experience increased power, flexibility, and control for your applications.
We can go on and on about all the things we love in the Laravel framework, however, don’t take our word for granted – give it a try and see for yourselves. Then we would like to hear what your thoughts are? FastComet wishes you all Happy Coding!
The latest tips and news from the industry straight to your inbox!
Join 30,000+ subscribers for exclusive access to our monthly newsletter with insider cloud, hosting and WordPress tips!