Laravel 7. What new framework features do we use for development?

6 October 2020

The Laravel web development framework is widely used in the IT industry. The popularity of this web framework is partly due to its adaptability to the specific needs of the user, as well as the ease of making various changes to the finished project created on its basis. Since March 3, 2020, this platform has received an update to version 7.

One of  the important  changes in the new version is the introduction of the Laravel Sanctum system, which now uses a simpler and more flexible user identification system in web applications and websites that have a one-page basis, as well as mobile applications and simple programming interfaces focused on use of authorization devices (tokens).


Laravel Sanctum can be installed using “Composer”:

laravel sanctum


After that, the Sanctum migration and configuration files must be published using the Artisan command:



If Sanctum will be used for authentication in a single page application, the Sanctum middleware must be added to the appropriate middleware group, as shown below:



The user has the opportunity to create several tokens that can be flexibly configured to obtain limited access permissions and perform a certain limited scope of functions. In addition, creating tokens in the new system has become less of a hassle, since there is no longer a need to create an open authorization protocol (OAuth).


To start issuing tokens, the user model must use the HasApiTokens:




A token can be created using the createToken:




Also, noteworthy are the benefits of the new authorization system, such as security improvements to cross-site request forgery (CSRF), cross-site scripting (XSS), and session authentication.

Other important changes in Laravel 7.0 are the Blade components. For example, a visualization (rendering) function was added using labels (tags). The ability to set attributes, adjust component classes, and preinstalled components has also been improved. The component is given a class that defines the data it receives, and the component template now has automatic access to all exposed methods and properties specified by the corresponding component class. Additional HTML properties (attributes) can be automatically modified using a variable ($attribute) that is included in the attribute set. At the same time, in the new version of the framework, all previous versions of the syntax of the Blade components are preserved.


For example, if the App\View\Components\Alert component is defined as:


The Blade component template is represented as:

In this case, the component can be displayed using the tag:

Laravel version 7 has also been improved with an update to the Guzzle HTTP client, which has a simpler and more concise programming interface that allows you to quickly create communication with web applications through HTTP requests. Moreover, when developing the Guzzle client for Laravel, the most likely situations of using this tool, as well as the experience of its use by developers, were taken into account. In particular, the specified client is able to quickly create a POST request to interact with JSON data.

In addition to the above, the updated client includes convenient and useful testing tools:

The update introduced the ability to quick string actions by introducing a new, more object-oriented string action library  for the string management tools previously introduced in the Laravel class (Illuminate\Support\Str). Using the Str::of method, you can create a free Illuminate\Support\Stringable object, and then add string manipulation methods:


Laravel 7.0 provides the ability to create multiple mail driversin one application. At the same time, each mail driver can be individually configured using a configuration file, and it is also possible to use several mail services within one application.

The mail driver settings are carried out using the mailer method, which allows you to send a message taking into account the set parameters:

The changes to the new version also affect the default Markdown mail template, which has been redesigned using the Tailwind CSS color palette. However, the template can be customized differently for specific tasks.

Compared to previous releases, Laravel 7.0 has received a more robust MySQL 8+ database queue so that the database driver can be used in relevant applications with high production volumes without fear of security issues. p>

Also, thanks to a new approach to matching cached routes, the new version of Laravel has been able to achieve a 2x speedup in processing requests in applications. This improvement is especially noticeable in large applications with more than 800 routes.

Laravel 7.0 framework added support for cross-origin resource sharing (CORS) by default.

A number of innovations in release 7.0 touched on the Artisan testing tool. Now you can use a convenient console with detailed information regarding the tests being carried out.

Also, a new console command for Artisan stub:publish has been added, which allows you to create and configure the so-called stub” files needed to create classes such as tests, controllers, migrations or tasks.

During development, it may be necessary to repeat an action, although the action should fail when a certain number of exceptions (maxExeptions) is reached. In Laravel 7.0, it is possible to specify the maximum allowed exceptions parameter.

For example, if an application cannot acquire a Redis lock, the action is executed 25 times within 10 seconds. However, if the action throws three unhandled exceptions, it will fail.

Summarizing, Laravel 7.0 has established itself as a reliable and flexible web development tool that has many useful features that simplify the process of creating projects and get rid of a number of limitations of previous releases.

The company VIS-A-VIS actively uses this framework in the development process, which allows us to achieve the best results that satisfy even the most demanding customer requests.

Did you like the article? - Share the link::