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 as well as advanced users – we thought that this would be a 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 allows us, end users to plan ahead when we need to perform upgrades, and also the dev teams using the software a way of knowing what is coming and when to expect it. Since Laravel 5.X update has been released roughly every six months. This announcement and all new releases have followed this schedule since 2015. Laravel always was on point with their schedule, and as previously discussed when 5.7 was released with the new 5.8 – now the older Laravel 5.7 will no longer receive feature bug fixes and updates, so this is something to be considered. Still, 5.7 will receive security updates until August 2019 which is an admirable commitment from the core team. As of now, Laravel 5.8 is the latest stable version and will receive bug fixes and updates until approximately August 2019 and security fixes until about 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 for international characters in email addresses is a small victory. Laravel’s built-in validation rule for email in 5.8 will now allow the use of international characters in email addresses if you have the following validation code below:
$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 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 learn more about migrating from Carbon 1 to Carbon 2 and how that 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 multiline strings and white space at the end of strings in your environment file.
Previously with the above example, it would have 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 any spaces at the end of the string, which previously was stripped from the environment variables. This is especially useful in various use cases like for example when multiline API keys are required 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 available to maintain functionality if you don’t want to rework your existing code, but as always it is a good practice to get 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 in terms of which parts of the environment we try to read and modify
– First-class support for multi-line variables
– No more trimming of values, you get them precisely as-is now
– Accept a list of paths to try in order looking for the dotenv file, rather than a single path
– Stronger validation of variable names 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 Feb 26, 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 significantly 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 instance 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!