Despite being an open source PHP framework, Laravel has been evolving consistently to meet the emerging trends in web application development. The latest long term support (LTS) version of Laravel was released officially in August. Laravel 5.5 enables 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. The developers can automate the process of migrating from Laravel 5.4 to Laravel 5.5 by using third-party tools like Laravel 5.5 Shift. But it is also important for PHP programmers to 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 earlier version of Laravel, developers have to put extra effort to add service providers to the app configuration file and register the relevant facades. But Laravel 5.5 has the capability to detect the service providers and facades automatically. It further registers the service providers and facades without requiring any manual intervention.
While working with Laravel 5.5, programmers can use resource classes to accelerate API development. They are no longer required to use an additional transformation layer between the Eloquent models and JSON requests. The resource classes make it easier for programmers to convert the models and model collections into JSON without using any transformation layer.
Automatic Registration of Console Commands
Earlier version of Laravel require programmer to list the custom commands manually to the console kernel through its $commands property. Laravel 5.5 enables developers to register custom commands more efficiently by calling the new load method from the kernel’s commands. Once the load method is invoked, it will scan a specific directory for console commands and register the console commands found in the directory automatically.
New Frontend Preset Options
Validation Rule Objects
Laravel 5.5 allows 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 app/Rules directory simply by running a new Artisan command. But each object rule can have only two methods -passes and messages. The passes method receives the name and value of attribute, whereas 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 needs to be attempted before failing. Laravel 5.5 enables developers to add a timeframe to the number of job attempts. A developer now has option to set time for abortion of job attempts. Hence, a job can be attempted within a specific amount of time.
The earlier versions of Laravel do not provide any features to simplify email layout testing. Hence, developers have to rely on third-party tools like Mailtrap to evaluate email layouts. Laravel 5.5 makes it easier for users to test email layouts by rendering emails directly to the browser. It even returns mailables directly from routes.
While using Laravel 5.5, the Laravel developers have option to make the application send notifications to individuals who are not stored as users. They can invoke the new Notification::route method to send on-demand notifications to individuals by specifying custom ad-hoc notification routing information.
Consistent Exception Handling
While working with earlier versions of Laravel, developers have to customize format of JSON validation error responses according to specific locations in the PHP framework. Laravel 5.5 enables developers to keep validation exception handling consistent and avoid customization. The developers can even control the JSON validation error message formatting with a single method.
Renderable and Reportable Exceptions
In addition to keeping exception handling consistent, Laravel 5.5 allows developers to define a render method directly on exceptions. Hence, the developers can include the custom response rendering logic in the exceptions without putting conditional logic in the event handler. They even have option to customize the reporting logic for each exception.
Laravel 5.5 comes with improved Redis and Memcached cache drivers with the capability to obtain and release atomic locks. The developers can take advantage of these improved cache drivers to obtain arbitrary locks by invoking a simple method. They can use the simple method to obtain a lock which prevents multiple processes to attempt 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. The developers can use the Route::redirect to easily define a route that redirects to a different URI. Likewise, the Route::view method makes it easier for programmers to define a route which a view. The programmers can further avoid defining a full route by using the shortcuts provided by these methods.
New Database Configuration Option
Laravel 5.5 enables developers to avail 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. It further allows developers to combine read operations and write connection if write operations are performed against the database during the same request cycle.
While using Laravel, developers accelerate view generation and rendition through a robust template engine like Blade. The latest version of the PHP framework comes with several improvements related to Blade. For instance, it allows Laravel developers to define custom conditional directives using Closures through a new method – Blade::if. Likewise, a developer can check the current status of a user more efficiently by using a number of shortcuts – @auth, @guest, @endauth and @endguest.
On the whole, 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 build custom web applications.