Despite being an open source PHP framework, Laravel has constantly evolved to meet emerging trends in web application development. The latest version of Laravel Long Term Support (LTS) was officially released in August. Laravel 5.5 allows developers to accelerate web application development by leveraging PHP 7.
At the same time, it comes with several new features, enhancements, and bug fixes to simplify custom web application development. Developers can automate the migration process from Laravel 5.4 to Laravel 5.5 by using third-party tools such as Laravel 5.5 Shift. But it is also important that PHP programmers understand the new features and changes in Laravel 5.5.
Overview of new features and changes in Laravel 5.5
Automatic package discovery
While working with an older version of Laravel, developers need to put more effort into adding service providers to the application configuration file and registering the relevant facades. But Laravel 5.5 has the ability to detect service providers and facades automatically. Plus, it registers service providers and facades without requiring any manual intervention.
Resource classes
While working with Laravel 5.5, programmers can use resource classes to speed up API development. They no longer need to use an additional transformation layer between Eloquent models and JSON requests. Resource classes make it easy for developers to convert models and model collections to JSON without using a transformation layer.
Automatic logging of console commands
The older version of Laravel requires the programmer to list custom commands manually in the console kernel via its $ commands property. Laravel 5.5 allows developers to register custom commands more efficiently by calling the new load method from kernel commands. Once the load method is invoked, it will scan a specific directory for console commands and log the console commands found in the directory automatically.
New frontend presets
The latest version of Laravel supports basic Vue scaffolding. But it allows developers to take advantage of a number of new frontend presets. Developers can run preset commands to switch from the Vue scaffold to the React scaffold. Similarly, they can use the default value of none for JavaScript scaffolding and remote CSS for the web application. However, the developer can take advantage of these frontend presets only in new Laravel applications.
Validation rule objects
Laravel 5.5 enables developers to add custom validation rules to a web application more efficiently using validation rule objects. A developer can create new validation rules in the application / Rules directory simply by running a new Artisan command. But each object rule can only have two methods: passes and messages. The passes method receives the name and value of the attribute, while the messages method returns the validation error message.
Time-based job attempts
Laravel allows developers to set the number of times a job or task should be attempted before failing. Laravel 5.5 allows developers to add a period of time to the number of job attempts. A developer now has the option to set a time for interrupting job attempts. Therefore, a job can be attempted within a specific time period.
Mailables renderable
Older versions of Laravel do not provide any features to simplify email design testing. Therefore, developers must rely on third-party tools like Mailtrap to evaluate email layouts. Laravel 5.5 makes it easy for users to test email layouts by displaying emails directly in the browser. It even returns mail directly from the routes.
Notifications on demand
When using Laravel 5.5, Laravel developers have the option to have the application send notifications to people who are not stored as users. They can invoke the new Notification :: route method to send on-demand notifications to people by specifying custom ad-hoc notification routing information.
Constant exception handling
When working with older versions of Laravel, developers need to customize the format of JSON validation error responses according to specific locations in the PHP framework. Laravel 5.5 allows developers to keep validation exception handling consistent and avoid customization. Developers can even control the format of the JSON validation error message with a single method.
Representable and reportable exceptions
In addition to keeping exception handling consistent, Laravel 5.5 allows developers to define a rendering method directly on exceptions. Therefore, developers can include custom response rendering logic in exceptions without putting conditional logic in the event handler. They even have the option to customize the reporting logic for each exception.
Cache lock
Laravel 5.5 comes with improved Redis and Memcached cache drivers with the ability to get and release atomic locks. Developers can take advantage of these improved cache handlers to obtain arbitrary locks by invoking a simple method. They can use the simple method to get a lock that prevents multiple processes from trying the same task before the application performs a specific task.
New routing methods
The updated version of Laravel makes it easier for developers to define routes by providing several new methods. Developers can use Route :: redirect to easily define a route that redirects to a different URI. Also, the Route :: view method makes it easy for programmers to define a route to view. Programmers can further avoid defining a full path by using the shortcuts provided by these methods.
New database configuration option
Laravel 5.5 allows developers to take advantage of a new database configuration option called sticky while configuring read / write database connections. As an optional value, sticky facilitates immediate reading of records written to the database during the current request cycle. Also, it allows developers to combine read and write connection operations if the write operations are performed on the database during the same request cycle.
Blade enhancements
By using Laravel, developers speed up the generation and rendering of views through a robust templating engine like Blade. The latest version of the PHP framework comes with several Blade-related enhancements. For example, it allows Laravel developers to define custom conditional directives using Closures through a new method: Blade :: if. Similarly, a developer can check the current state of a user more efficiently by using various shortcuts: @auth, @guest, @endauth, and @endguest.
Overall, Laravel 5.5 comes with several new features and improvements. These new features make PHP programmers more productive and reduce the amount of time and effort required to create custom web applications.