Laravel 10: Features and Updates

With the growing demand for exceptional services and updates in the market, the Laravel core team is determined to leave no stone unturned in making Laravel the top choice for business owners. It is with this in mind that they present their latest investment in the franchise: Laravel 10. In this article, we will introduce you to the new features and updates in Laravel 10 that will capture the attention of developers and business leaders and encourage them to upgrade their existing Laravel applications.

Laravel 10, date de sortie

Laravel and its official packages follow the Semantic Versioning methodology, which involves releasing major framework updates once a year during the first quarter. Minor updates may be released concurrently as needed. With the release date of Laravel 10 set for February 13, 2023, the latest version of the framework has arrived, bringing new features and significant updates. Previously, a new version of Laravel was released every six months. However, after the release of Laravel 9 in February 2022, the core team adopted an annual release schedule, as follows:

  • Laravel 9: February 8, 2022       
  • Laravel 10: February 13, 2023   
  • Laravel 11: February 6, 2024

According to the official Laravel information page, Laravel 9 will receive scheduled bug fixes until August 8, 2023, and security patches until February 6, 2024. Laravel 10 is expected to receive bug fixes until August 6, 2024, and security patches until February 4, 2025.

What's New in Laravel 10: Latest Features and Updates

L’équipe derrière le framework s’efforce toujours d’apporter le meilleur à ses utilisateurs, c’est pourquoi il est recommandé d’utiliser des contraintes de version telles que ‘^10.0’ lorsqu’on fait référence au framework ou à ses composants dans une application ou un package. Car, les nouvelles versions peuvent être accompagnées de modifications et de mises à jour notables. La version actuelle de Laravel 10 comprend également plusieurs améliorations substantielles qui bénéficieront aux propriétaires de produits. Examinons ces changements de plus près :

Removal of support for PHP 8.0

Laravel 10 no longer supports PHP 8.0, and you should upgrade to PHP 8.1 or 8.2. While it’s not necessary to immediately update your Laravel applications to the latest version upon release, thorough testing is always recommended, especially for projects with clients or paid staff. Additionally, support for Predis v1 ended with PHP 8.0, and you should upgrade to Predis v2.

Introduction to Laravel Pennant

Laravel Pennant is a simple and lightweight feature set that allows you to easily deploy new features within your application. It includes an A/B testing interface, supports trunk-based development strategies, and more. Feature flags allow you to enable or disable a feature at runtime without modifying the code.

Easy process management

Laravel offers a simple and comprehensive API for the Symphony Process component, allowing you to easily run external processes within your Laravel application. This process functionality addresses common use cases, providing a significantly improved development experience.

Validation rules that can be invoked by default

With Laravel 9, the “–invokable” flag had to be added after the `artisan` command when creating a new invocable rule. However, in Laravel 10, you can simply run the following command to create a new invocable rule:

php artisan make:rule CustomRule

The template code is simple and easy to understand, which makes it less intimidating for developers to create their own custom validation rules.

Skew code of the application with type declarations

In the past, Laravel used DocBlocks in its skeleton code to clearly explain the function of a particular piece of code and the responses or parameters it provides. However, with the new type declarations, all user code within the framework will now include type hints and return types. These improvements offer additional benefits and do not affect backward compatibility with the core framework. This includes method arguments, return types, the removal of unnecessary annotations where possible, the exclusion of the `Types` property, and allowing users to access closure arguments.

DispatchNow() removal

In Laravel 10, the ‘dispatchNow()’ method was removed because it was deprecated in Laravel 9 in favor of ‘dispatchSync()’. It is essential to replace it in all your existing projects, as it is a break change, but the solution is simple.

Laravel 9 Depreciations

With the recent Laravel update, the team is gradually removing deprecated methods from Laravel 9 into the Laravel 10 branch. The updated Laravel documentation regarding the update process, including a list of all deprecated methods and packages, is available in the documentation.

Those planning to upgrade their projects to Laravel v10 will need to rewrite their code with a new approach to achieve the desired result. Here are some of the deprecations and removals from branch 9 to the main branch:

  • The Route::home method, which was deprecated in Laravel 9
  • The getBaseQuery method, which has a toBase equivalent
  • The MaintenanceModeException class, which is no longer used
  • The MocksApplicationServices trait
  • The Mail::failures method in the fake email
  • A recommendation to use `$casts` instead of the `$dates` property, which is obsolete.
  • The assertTimesSent() method
  • Support for Predis 1 and doctrine/dbal 2 is no longer available
  • All deprecations related to doctrine/dbal since Laravel dropped support for version 2.

Should you upgrade to Laravel 10?

It’s important to note that Laravel is an open-source framework, so every time you install a new instance on your device, you own the codebase. Even if your version is no longer supported, your application will still work. However, you will be responsible for maintaining the version yourself. It’s advisable to prioritize stability over framework updates. Only consider upgrading to Laravel 10 if:

  • Your current Laravel application is stable and functioning correctly.
  • The update will provide a necessary feature or fix a critical bug that will improve your application’s performance.
  • You thoroughly tested your application before implementing the upgrade in the production environment.

How to upgrade from Laravel 9 to Laravel 10

With the official release of Laravel v10, updating your current Laravel application to the new version will be a breeze with Laravel 10.x Shift. This tool automates the upgrade from Laravel 9 to Laravel 10, saving you up to two hours of valuable time. It’s important to note that both Laravel and Laravel 10.x Shift will receive regular updates, and Shift users can request a new update as needed.

Requirements

To upgrade your current Laravel application to Laravel 10, a few essential conditions must be met:

  • Your Laravel application must be on Laravel 9 or higher.
  • Your server must be equipped with PHP 8.1 or a more recent version.

Basic updates

The Shift automates most of the updates described in the Laravel Update Guide, including the following  :

  • Updates to the main Laravel project files
  • New methods for interface changes
  • Adding PHP-like hints to the Laravel application
  • Converting the obsolete $dates property to $casts
  • Updated core dependencies for Laravel 10 and PHP 8.1
  • Removal of redundant typing in PHP DocBlocks
  • Detection of obsolete code in the application code.

Additional updates

In addition to the core updates, Shift also provides additional updates mentioned in the Laravel Update Guide, such as:

  • Modernization of PHP syntax, including the use of the null-safe operator and short arrays.
  • Option to apply your preferred code style
  • Adoption of tuple syntax and class-based routes
  • Conversion to anonymous migration
  • Automated changes required for PHPUnit 9
  • Transforming access to Faker properties into method calls
  • Updated configuration files to reflect Laravel 10 versions
  • Increased dependency constraints for popular packages.

Manual updates

Although the Laravel 10.x Shift aims to automate as many updates as possible, there may be some updates that cannot be automated. In such cases, it detects these updates and provides detailed instructions as comments in the pull request, outlining the steps required for manual implementation.

While The Shift Project strives to detect and automate updates for popular dependencies, manual implementation may still be necessary. It is recommended to review the changelog for dependencies and any additional changes to ensure a successful update.

Conclusion

We hope this article has given you a comprehensive overview of the latest version of the framework. If you’re a business owner hesitant to upgrade your existing Laravel application to Laravel 10, or if you’re considering a new project and wondering whether Laravel is the right solution for your needs, we highly recommend partnering with a Laravel development company like Ezway Technology. Our team of experts will guide you through every step of your web application development, minimizing any stress or concerns you may have.