New features and upgrades in Laravel 5.7

New features and upgrades in Laravel 5.7 with explanation

Laravel is one of the best PHP frameworks in 2018. The first version released only in June 2011, it has made significant improvements up to this date. Laravel is always a hot topic for PHP programmers in its large active community. An upcoming version is laravel 5.7 which will require PHP greater than or equal to 7.1.3.

After the release of Laravel 5.7, Laravel 5.6 will still continue to get bug fixes until August 7th, 2018 and security fixes until February 7th, 2019.

Similarly, Laravel 5.7 will get support for bug fixes and security fixes until February 2019 and August 2019 respectively.

Laravel has been continuously adding useful features since it’s the first release. Ever been excited about new features in laravel? Yeah! you should be because new exciting features are coming to laravel 5.7. The main features new includes Laravel Nova, optional email verification to the authentication scaffolding, support for guest users in authorization gates and policies, Symfony dump-server integration, localizable notifications.

Let’s discuss each feature in details.

1Laravel Nova

Laravel Nova is a laravel package which is used to create a beautiful admin panel. You can install it in your new project or even in the existing project via composer. Good news is that it even supports for laravel 5.6. It uses Vuejs, Vue Router, and Tailwind as frontend. As Tailwind.css was recently released which is a utility CSS framework. You can find more about in its official documentation.

Laravel Nova includes from the basic CRUD operations to complex search, filters, lenses, metrics operations. If you want to read more about this package, you can read a detailed article by Taylor Otwell on medium or it’s official documentation.

2Email Verification

As you all are familiar with the laravel detault authentication system. Laravel now even has optional email verification to this authentication. A new column email_verified_at has been added in users table. You don’t need to add yourself, it comes with default migration. You just need to run migration.

The User model should implement the MustVerifyEmail interface to suggest new user to verify their email address. So, your User model looks like below:

After implementing MustVerifyEmail interface, newly registered user get an email address containing a verification link to activate the account. So, when user clicks on the link, the account is activated.

Along with email verification, laravel 5.7 also provides a middleware which restricts only for verified emails only. So, this can very handy and useful for backend functionality.

To protect your routes only for verified emails, attach the middleware in the routes.

3Guest User Gates / Policies

Guest User Gates is another useful features that is comming in laravel 5.7. Until now, laravel used to return false when visitors try to access access unauthenticated routes. But in laravel 5.7, you can type-hint the model or anything or simply return null to return accordingly.

4Symfony Dump Server

Have you ever thought of dumping data in console or to an external HTML file? Then, it’s great that laravel 5.7 will have a built-in feature for this. You can simply dump your data in console or even in html file.

This command is very handy and a lot useful for debugging purpose without interrupting the application runtime.

This command runs a server in the background. It receives data sent from the application and display through the console. Never to worry that, when this command is not running, dump() works as default.
image image
You can find more information about this package in its github directory.

5Notification Localization

In laravel 5.7, you can send notification other than the current language. For this, you need to specify the language you need to used in notification inside locale method. For example:

Localization of multiple notifiable entries may also be achieved via the Notification facade:

6Improved Error Messages

You can now track down the error messages more easily in laravel 5.7. The reason behind this is that laravel 5.7 now uses bouncer package developed by Joseph Silber. This will show errors message on dynamic calls and Eloquent models.

In laravel 5.7, you can directly get the clear error message without other underlying object messages. Joseph introduced in one of his tweets

7URL Generator and Callable Syntax

A new callable-like syntax for action URLs is coming to Laravel 5.7. It is same like the in laravel 5.6 which accepta s string in action method. This main benefit of this new syntax is that you can directly navigate to the controller from it.

Basic syntax for callable syntax:

8Resources Directory Changes

There will be a slight change in the resources directory in laravel 5.7. There is nothing new but the assets directory will be removed and js and sass directory will be opt out to resources directory. Taylor announced in one of his tweets that resources directory will be flattened as below:

When you upgrade the laravel version, you don’t need to reconstruct the resources/asset directory according to the newer directory structure. It will works will older structure.

9Paginator Links

This tiny feature in laravel 5.7 may be useful in many cases. This feature will help to control how many additional links are displayed on each side of the paginator’s URL “window”.

If you have used paginations before then you might have noticed three links which is by default. But, you can explictly define in laravel 5.7

10Filesystem Read / Write Streams

Laravel’s Flysystem integration now offers readStream and writeStream methods:

Great! I hope you are now ready the for new version of laravel 5.7. Thanks for reading this article.