What’s new in Laravel 5.8

We take a look at new features and changes in Laravel 5.8 you should be aware of whether starting a new project or upgrading an existing one.

Laravel 5.0 was released in February 2015 and a 5.x update has been released roughly every six months since then. As 5.7 was released in September 2018, we can expect to see the initial release of Laravel 5.8 sometime around March 2019.

In this article we’ll take a quick look at some new features or important changes that you should be aware of whether creating a new project from scratch or updating an existing one.

As always, before upgrading a Laravel version, be sure to carefully read and understand the upgrade guides to ensure a smooth upgrade process.

So here’s a few important updates coming to Laravel 5.8.

Email validation:

Laravel’s built in validation rule for email in 5.8 will now allow for international characters in email addresses.

If you have the following validation code:

$request->validate([ 'email' => 'email', ]);

And attempt to validate an email address such as hej@bär.se in 5.7, it will fail. However it will pass validation in 5.8.

In 5.7 the validation logic did not match with the logic used by SwiftMailer (the PHP mailer library used by Laravel), but now they both conform to RFC6530 compliance.

dotenv 3.0:

Laravel 5.8 will support the relatively new dotenv 3.0 to manage your project’s .env environment file.

The key new features in dotenv 3.0 are support for multiline strings and white space at the end of strings in your environment file, for example, something like:

DEVELOPMENT_APP_KEY="specialstringfor 
thisapp"

Will only return specialstringfor, whereas in 5.8 the whole specialstringfor thisapp will be parsed. It will also respect any spaces at the end of the string, which were previously stripped from the environment variables.

This is a great update for situations where multiline API keys are required for security.

Mailables directory name change:

This is less of a new feature but an important element you will need to be aware of when upgrading a project.

If you have mailables in your project and you have customised the components using the php artisan vendor:publish command, the folder names have changed slightly, namely the /resources/views/vendor/mail/markdown directory is now named /resources/views/vendor/mail/text. This is because both folders can contain markdown code for making good looking responsive html templates with plain text fallbacks. It’s more logical to call the markdown folder text

New error page templates:

Laravel 5.8 will ship with new error pages featuring a very minimalist design that is intended to be more suitable for a range of websites and web apps without needing to be re-designed to fit a theme.

Laravel 5.7 404 view (top) and 5.8 404 view (bottom)

You can still customise the error pages or import your previous designs if you prefer them(see our tutorial on custom Laravel error pages).

Array and String helper functions are deprecated:

All array_* and str_* global helpers have been deprecated and will be removed in Laravel 5.9. There are Arr:: and Str:: facades that should be used instead. There will be packages available to maintain functionality if you can’t or don’t want to re-work existing code but it is good practice to get used to the new commands now if you need to use them.

An existing array_ function such as:

function array_add($array, $key, $value)

Should be replaced with:

Arr::add($array, $key, $value)

Similarly string helper functions such as:

function str_contains($haystack, $needles)

Should be replaced with:

Str::contains($haystack, $needles);

In fact, if you check the 5.8 code for array_* and str_* global helpers you’ll see they already simply use the facade version.

Caching — ttl now in seconds instead of minutes:

If you are using Laravel’s caching functions take note that if you are passing an integer to the cache function in 5.8 it will apply the time to live in seconds and not minutes as it currently is in 5.7, so this command:

Cache::put('foo', 'bar', 30);

Will store the item for 30 minutes in Laravel 5.7 and 30 seconds in Laravel 5.8. A simple but important difference!

JSON values in MySQL:

If you are storing JSON values in MySQL and MariaDB database columns, in 5.7 Laravel would return values wrapped in double quotes. 5.8 returns the same values in cleaner strings.

The following is the example from the Laravel upgrade guide which illustrates the change:

$value = DB::table('users')->value('options->language');

dump($value);

// Laravel 5.7…
'"en"'

// Laravel 5.8…
'en'

Carbon version 2 support:

You will now have the option of using Carbon 1 or Carbon 2 for your DateTime functions in Laravel 5.8. Check the Carbon migration guide if you intend to use Carbon 2.

Nexmo and Slack Notification channels:

The Nexmo and Slack Notification channels have been removed from the main Laravel project and extracted into first-party packages.

To continue using Slack or Nexmo functionality in your project you’ll need to use:

composer require laravel/nexmo-notification-channel 
composer require laravel/slack-notification-channel

They can then be configured and used as before.

So that pretty much covers the key changes you should be aware of. We always like checking out new software releases at Welcm Software, and look forward to the release of 5.8 soon.


Like this story? Please follow us on Twitter.

At Welcm we design, develop and support web applications and mobile apps. We specialise in the Laravel framework.

If you have a project you would like to discuss please send an enquiry from our contact page, email us at enquiries@welcm.uk or call us on 01252 950 650.

We also make Visitor Management Easy at https://welcm.ly

Originally published at welcm.uk.