avatarREUBEN SHUMBA

Summary

Laravel 10 introduces significant updates and features, including PHP 8.1 support, enhanced security, and new testing and development tools, while adopting an annual release cycle and deprecating certain methods and packages.

Abstract

Laravel 10, the latest iteration of the Laravel PHP framework, has been released with a shift to an annual update cycle, initially planned for February 7, 2023, but released on February 14, 2023. This version requires PHP 8.1 as a minimum and supports PHP 8.2, ensuring alignment with the latest PHP features. It includes updates to official Laravel packages, introduces native type declarations, and makes all validation rules invokable by default. Laravel 10 also streamlines column modification in databases, improves eager loading optimization, and integrates the xxHash algorithm for faster hashing. Notable new packages include Laravel Pennant for feature flags and Laravel Process for CLI process interaction. The framework also enhances security with updates to the Timebox class and standardizes the dispatch() method behavior. Laravel 10 is poised to provide developers with a robust and innovative platform for building web applications, with a structured support policy that guarantees bug fixes for 18 months and security updates for two years.

Opinions

  • The author suggests that upgrading to Laravel 10 should be a strategic decision based on the stability of the current application, the need for new features, and thorough testing.
  • The shift to an annual release schedule is seen as a positive change, allowing for more focused development and ample time dedicated to each version.
  • The integration of PHP 8.1 and 8.2 support is highlighted as a significant advancement, keeping Laravel in line with the latest PHP advancements.
  • The deprecation of certain methods and packages, such as Route::home and support for PHP 8.0, is acknowledged as part of the framework's evolution.
  • The author expresses enthusiasm about the new features and improvements, particularly the new first-party packages like Laravel Pennant and the enhancements to the database query builder.
  • The author encourages developers to stay informed about upcoming features in Laravel 11, suggesting that the framework will continue to evolve and offer new tools and capabilities.
  • The article concludes with a call to action for readers to follow the author, engage with the content, and reach out with any questions, indicating a desire to foster a community of Laravel developers.

What’s New in Laravel 10: A Deep Dive Into the Latest Updates and Features

Image from google search

What’s New in Laravel 10: A Comprehensive Guide to Latest Updates and Features

With over a decade of evolution, Laravel continues to stand as a prominent PHP framework. Laravel 10, the latest version, introduces an array of exciting features and enhancements. In this article, we’ll take a deep dive into these updates, fixes, and deprecated methods to keep you abreast of what Laravel has to offer.

Laravel Release Schedule

Traditionally, Laravel aimed for two major releases annually, occurring every six months. However, Laravel 10 marks a shift in this cycle, with Taylor Otwell, the framework’s creator, announcing an annual release schedule. This adjustment allows for a more focused development approach, dedicating ample time to each version. Laravel 10 was initially set for release on February 7, 2023, but due to additional refinements, it landed on February 14, 2023.

Laravel Support Timeline

Laravel follows a structured support policy, providing bug fixes for 18 months and security updates for two years for all versions. As of Laravel 10:

  • Laravel 9: Bug fixes until August 8, 2023, and security fixes until February 6, 2024.
  • Laravel 10: Bug fixes until August 6, 2024, and security fixes until February 4, 2025.
  • Laravel 11 (expected): Bug fixes until August 5, 2025, and security fixes until February 3, 2026.

Should You Upgrade to Laravel 10?

Before jumping into the new features, it’s essential to consider when to upgrade. Upgrading should be a strategic decision based on:

  • Stability: Ensure your application is stable with the current version.
  • Need: Upgrade if the new features address specific requirements or fix existing issues.
  • Testing: Thoroughly test the application before pushing upgrades to production.

Laravel 10 Hot Updates

Let’s explore the standout features and updates that Laravel 10 brings to the table.

1. PHP 8.1: At the Heart of Laravel 10

Laravel 10 embraces PHP 8.1 as the minimum-required version, leveraging features like readonly properties and array_is_list. This aligns Laravel with the latest PHP advancements.

Example:

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
  // Implementation
}

2. Support for PHP 8.2

Released shortly before Laravel 10, PHP 8.2 support is seamlessly integrated. Laravel’s entire ecosystem, including Forge, Vapor, and Envoyer, is ready for PHP 8.2.

Note: Ensure your environment is ready for PHP 8.2 to harness its benefits.

3. Laravel Official Packages Upgrade

Laravel’s official packages undergo consistent updates to stay aligned with the framework. Notable packages, including Breeze, Dusk, Jetstream, and Scout, are upgraded for Laravel 10 compatibility.

Update Command:

composer require laravel/jetstream

4. Predis Version Upgrade

Predis, a robust Redis client, sees an upgrade in Laravel 10. The framework no longer supports Predis 1, emphasizing the use of the official PHP extension for Redis interaction.

Migration:

// Laravel 9
$client = new Predis\Client('tcp://127.0.0.1:6379');

// Laravel 10
$client = new Redis();

5. Native Type Declarations

Laravel 10 introduces native type declarations, enhancing code clarity and aiding code editors with better auto-complete features.

Example:

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
  // Implementation
}

6. All Validation Rules Invokable by Default

In Laravel 9, invokable validation rules required an additional flag. Laravel 10 simplifies this by making all rules invokable by default.

Command:

php artisan make:rule CustomRule

7. Native Column Modification Support

Laravel 10 streamlines column modification, eliminating the need for the DBAL (doctrine/dbal) package when using the change() method.

Example:

// Laravel 9
$table->integer('user_balance')->change();

// Laravel 10
$table->bigInteger('user_balance')->unsigned()->default(0)->comment('balance')->change();

8. Column Type Native Retrieval

Retrieve column types without relying on the doctrine/dbal package. Laravel 10’s Schema::getColumnType method returns the actual column type, improving compatibility across databases.

Usage:

$type = Schema::getColumnType('products', 'price');

9. Faster Hashing Algorithm

Laravel 10 adopts the xxHash algorithm for faster hashing. Developers should verify third-party package compatibility, as some may rely on specific file name formats.

Update Consideration: Check third-party packages for SHA-1 hash dependencies.

10. whereExists() Method Support for Eloquent Builder

Laravel 10 enhances the whereExists() method, allowing direct usage of an Eloquent Builder as a nested query.

Improved Syntax:

// Laravel 9
Order::whereExists(function ($query) {
  $query->from('products')->whereColumn('products.order_id', 'orders.id');
});

// Laravel 10
Order::whereExists(Product::whereColumn('products.order_id', 'orders.id'));

11. Eager Loading Optimization

Optimizations in Laravel 10 address unnecessary queries during eager loading when no keys are present.

Performance Enhancement: Eager loading relations without keys now avoids unnecessary queries.

12. $path Optional for Filesystem Methods

Laravel 10 makes the $path parameter optional for various filesystem methods, simplifying file storage operations.

Simplified Storage:

// Laravel 9
Storage::disk('s3')->putFile('post/images', $uploadedFile);

// Laravel 10
Storage::disk(Disk::PostImages)->putFile($uploadedFile);

13. Database Expressions and Grammar-Specific Formatting

A notable feature in Laravel 10 is the improved handling of multiple databases, allowing cleaner expression classes for various functionalities.

Expression Classes: Create reusable expression classes for concise database operations.

Example:

// Laravel 9
DB::table('visitors')
  ->when(isPostgreSQL(), fn ($query) => $query->select(DB::raw('coalesce(NULL, "user", "guest") AS "First Visitor"')))
  ->when(isMySQL(), fn ($query) => $query->select(DB::raw('coalesce(NULL, `user`, `guest`) AS `First Visitor`')));

// Laravel 10
DB::table('visitors')->select(new Alias(new Coalesce([NULL, 'user', 'guest']), 'First Visitor'));

14. SQL Server Update To Use FETCH and OFFSET for Queries That Do Not Include an orderBy

Laravel 10 introduces an SQL Server update for optimized queries without orderBy, improving speed by 33%.

Query Enhancement:

// Laravel 9
DB::table('users')->skip(10)->take(5)->get();

// Laravel 10
DB::table('users')->offset(10)->limit(5)->get();

15. PHPUnit 10 Support

Laravel 10 seamlessly integrates with PHPUnit 10, providing developers with the latest tools for unit testing.

Update PHPUnit:

composer require --dev phpunit/phpunit ^10.0

16. Security Improvements for Timebox Class

Enhancements in the Timebox class of Laravel 10 bolster security against timeless timing attacks.

Usage:

$timebox = new Timebox(now(), now()->addMinutes(30));

17. dispatch() Method Behavior Standardization

The behavior of the dispatch() method is standardized across Laravel 10, aligning with the global dispatch() helper function.

Standardized Dispatch:

// Laravel 9
dispatch(new Job())->dispatch();

// Laravel 10
dispatch(new Job());

18. Laravel Pennant: Feature Flags Simplified

A new first-party package, Laravel Pennant, simplifies feature flag management, offering an easy-to-use solution for maintaining and checking feature flags.

Install Pennant:

composer require laravel/pennant

19. Laravel Process Interaction

Laravel 10 introduces Process Interaction, streamlining testing and running CLI processes with a straightforward API.

Process Interaction:

use Illuminate\Support\Process;
$process = Process::fromShellCommandline('php artisan migrate');
$process->run();

20. Pest Scaffolding

Pest test scaffolding is now enabled by default in Laravel 10, providing a powerful testing environment out of the box.

Test Scaffolding:

php artisan test

21. String Password Helper Function

Laravel 10 introduces a convenient Str::password function for generating random and secure passwords with a specified length.

Password Generation:

$password = Str::password(12);

Deprecated Methods and Packages

With progress comes change, and Laravel 10 bids farewell to certain methods and packages. Key deprecations include dropping support for PHP 8.0, removal of deprecated methods like Route::home (deprecated in Laravel 9), and adjustments to the usage of dispatchNow in favor of dispatchSync. Additionally, the $dates property is deprecated in favor of $casts.

How To Install Laravel 10

Getting started with Laravel 10 is a breeze, with multiple installation methods catering to different preferences.

Install Laravel 10 on MacOS

For MacOS users, leveraging Docker and Laravel Sail simplifies the installation process. A single terminal command ensures a smooth setup, with subsequent use of Sail to run the project.

MacOS Installation:

composer create-project laravel/laravel my-laravel-app
cd my-laravel-app
sail up

Install Laravel 10 on Windows 10 and 11

Windows users can also utilize Docker Desktop for a quick Laravel 10 installation. Enabling Windows Subsystem for Linux 2 (WSL2) or Hyper-V Backend Feature is necessary before running the installation command.

Windows Installation:

composer create-project laravel/laravel my-laravel-app
cd my-laravel-app
sail up

Install Laravel 10 With Composer

Composer remains a versatile tool for Laravel installation on both macOS and Windows. After ensuring PHP ≤ 8.1, node, npm, and Composer are installed, Laravel Installer or Composer can be used to create a new Laravel 10 application.

Composer Installation:

composer create-project laravel/laravel my-laravel-app
cd my-laravel-app
php artisan serve

How To Install Laravel 11

While Laravel 11 is slated for release in the future, developers can already explore its features by using the -dev flag during installation with Laravel Installer or Composer. This installs Laravel 11 from the master branch, offering a preview of upcoming features.

Preview Laravel 11

composer create-project laravel/laravel my-laravel-app --dev
cd my-laravel-app
php artisan serve

Conclusion

Laravel 10 introduces a plethora of features and improvements, enhancing the development experience for PHP developers. Whether you’re upgrading an existing application or starting a new project, Laravel continues to be a robust and innovative framework that empowers developers to create elegant and scalable web applications. Stay tuned for Laravel 11, where the framework is expected to evolve even further, bringing more tools and capabilities to the Laravel ecosystem.

Stay tuned!!! I will be back with some more cool Laravel tutorials in the next article. I hope you liked the article. Don’t forget to follow me 😇 and give some claps 👏. And if you have any questions feel free to comment. Thank you.

Thanks a lot for reading till the end. Follow or contact me via: Email: [email protected] Github: https://github.com/reubenshumba LinkedIn: https://www.linkedin.com/in/reuben-shumba-a72aaa157/ BuyMeCoffee: https://www.buymeacoffee.com/reubenshumba REUBEN SHUMBA

Laravel
Laravel Framework
Laravel 10 Features
Laravel 11
Laravel News
Recommended from ReadMedium