Laravel framework is widely popular since its inception. So what is so great about its offerings to PHP developers? Laravel provides simplified PHP development so that even beginners can proactively create websites with efficiency and speed. When the latest version Laravel 10 was introduced, it came with abundant features and functionalities. At the onset of the new version launch, developers anticipated it to be more complex. On the contrary, it stunned PHP developers with its most impressive and user-friendly fixes, features, and freshly deprecated methods and packages.
The article will take you on a journey through Laravel 10 and will serve as a guide to use as a reference. So bookmark this page and revisit it from time to time.
Laravel 10 Latest Features and Upgrades:
Laravel 10 got published on February 14, 2023. It will fix bugs until August 6, 2024, and security fixes by February 4, 2025. As a developer, you can upgrade to Laravel 10 if you find:
- Your application is stable and functions with zero problems with the current version.
- You want to add a feature that your application needs or you want to fix a problem experienced by your application for a long time.
- You are ready to test your application before upgrading the changes and further pushing it into production.
The new features of the latest version of Laravel for backend development are as follows:
PHP 8.2
Laravel 10 can utilize PHP 8.2 features without putting in any sort of extra effort. The entire Laravel ecosystem such as Vapor and Forge can use PHP 8.2 now.
Laravel Official Package Upgrade
The framework can now be professionally maintained regularly including its official packages. Some of the recent official Laravel packages updated to support Laravel 10 are:
- Dusk
- Passport
- Breeze
- Cashier Stripe
- Horizon
- Scout
- Jetstream
- Pint
- Valet
- Installer
- Sail
In addition, Vue, Rails, Svelte, and React are now supported by Laravel 10
Predis Version Upgrade
Predis is a powerful Redis client for PHP that provides tools for optimizing caching for a pleasant user experience. Laravel has previously worked nicely with both Predis versions 1 and 2. However, with the introduction of Laravel 10, Predis 1 support has been terminated.
Although the Laravel documentation recommends Predis as the go-to package for Redis interactions, you may also use the standard PHP extension. This addon provides an interface for communicating with Redis servers.
Native Type Declaration
Previously, Laravel used DocBlocks in its initial code to provide explanations about what a particular piece of code can accomplish along with the types of inputs or outputs it deals with. Now when native-type declarations in Laravel 10 got introduced, a major shift is seen gradually.
Here is an example:
/**
* Determine whether the user can create models.
*
* @param {{ namespacedUserModel }} $user
* @return IlluminateAuthAccessResponse|bool
*/
public function create({{ user }} $user)
{
//
}
Will look like below:
/**
* Determine whether the user can create models.
*/
public function create({{ user }} $user): bool
{
//
}
With the updates come enhanced experiences for the developers. Things are far smoother when working with your code. IDEs will have a clearer understanding of what parameters and responses they need to expect. This added clarity isn’t always achievable using the basic types in PHP. Code editors can now improvise auto-complete features, ultimately making their coding process more efficient.
Invokable Validation Rules by Default
For Laravel 9, you needed to add an -invokable flag after the Artisan command for invokable validation. Now, with Laravel 10 all rules are invokable by default. All you need is just to run the following command to create a new invokable rule in Laravel 10.
Php artisan make:rule CustomRule
Native Column Modification
Laravel 10 now can use the schema::getColumnType method and need not rely on the doctrine/dbal package. Currently, Schema::getColumnType is used with DBAL to get the column type. In simple terms, DBAL (Database Abstraction Layer) translates different types of columns in your database to a format it can work with. However, it doesn’t handle all the column types that Laravel uses across different databases.
Now, in Laravel 10, things have changed. There’s a new method called Schema::getColumnType that provides precise column type instead of just the translated version. You can create tests that check how the system modifies native columns. You can also use this method to get either the name of the data type or the entire definition of a specific column.
Schema::getColumnType('products', 'price'); // decimal
Rapid Hashing Algorithm
xxHash is a hashing algorithm that is extremely fast. It is intended to provide extremely diversified and distributed outputs, reducing the likelihood of data collisions. With PHP 8.1 now supporting xxh128 and Laravel 10 running on PHP 8.1, having this solid hashing method integrated into Laravel 10 is a huge benefit.
Taylor, the inventor of Laravel, did, however, bring out during his assessment that certain external packages may demand file names to match the exact syntax of the old SHA-1 hash, which was previously used for hashing in Laravel. This implies that if you’re thinking about upgrading to Laravel 10, make sure any third-party packages you’re using in your application are compatible with the new hashing configuration.
Support for Eloquent Builder
Previously, while using where exists () method in Laravel, setting up the nested query meant dealing with closures. Now, Laravel 10 brings a convenient enhancement. Now, directly use an Eloquent Builder as the nested query., enabling flexibility to employ custom builder methods, model scopes, and more. For instance, the conventional process for using whereExists() would be something like this:
Order::whereExists(function ($query) {
$query->from('products')->whereColumn('products.order_id', 'orders.id');
});
With Laravel 10, this can be done:
Order::whereExists(
Product::whereColumn('products.order_id', 'orders.id')
);
Eager Loading Optimization
One of the compelling features of Laravel 10 is fast loading optimization. This happens when no keys are to be loaded and come with a fixed change tackling current issues. Here, eager loading relations cause more executions of impossible queries. Previously, even if there were no keys to load, Laravel would still run a query that resulted in no data being fetched. As per the new update, Laravel 10 is smarter. It checks if there are any keys to load in the first place. If not, it simply gives you an empty collection, saving you from running unnecessary database queries. This change streamlines the process and makes your code more efficient.
Optional $path for Filesystem Method
The new version gives options where to choose $path parameter. You can use the below methods:
FilesystemAdapter#putFile
FilesystemAdapter#putFileAs
UploadedFile#store
UploadedFile#storeAs
UploadedFile#storePublicly
UploadedFile#storePubliclyAs
Instead of doing this, you can use the below command to store an uploaded file on any backup platform:
Storage::disk('s3')->putFile(‘post/images', $uploadedFile);
…we can now do this:
Storage::disk(Disk::PostImages)->putFile($uploadedFile)
Grammar Specific Formatting and Database Expressions
At the onset of its launch, Laravel 10 got this feature updated by a team to address the big challenge while working with multiple databases. Previously, while working with PostgreSQL and MySQL, if you wish to return the first value of a list, we wrote raw database code :
We use the above code to return the first non-null value named as the first visitor. So instead of writing complex database code from scratch, we can make reusable expression classes that handle these complex database tasks for our queries. This means we don’t have to keep writing intricate database code every time we want to use advanced database functions.
PHPUnit 10 Support
Laravel 10 is highly supportive to PHPUnit 10 used for unit testing. Also, Laravel 10 will support both the previous versions 9 and 8 of PHPUnit 10.
Enhancing Security Measures for the Timebox Class
Laravel 10 comes with security improvements for the Timebox Class. This tool focuses safeguard the application from timeless timing attacks. It uses hasValidCrdentials method and can handle all exceptions arriving at the time of Timebox’s callback execution.
Laravel Process Interaction
Process Interaction is specifically designed to streamline the testing process and execute command-line interface processes. This new feature comes with a user-friendly API that considerably simplifies the testing procedures. Now handling CLI processes is so easy and less cumbersome. Let us delve into a small illustrative example presented by Taylor Otwell who has created Laravel:
use IlluminateSupportFacadesProcess;
$result = Process::run('ls -la');
$result->successful();
$result->failed();
$result->exitCode();
$result->output();
$result->errorOutput();
$result->throw();
$result->throwIf(condition);
As you see the code is so simple and clear. Further, check out the building processes, things only get better.
$result = Process::timeout(60)->path(base_path())->env([...])->run('ls -la');
$result = Process::forever()->run('ls -la');
For using this new feature in testing, a fake process may be created like this:
Process::fake([
'ls *' => Process::result('Hello From Kinsta'),
]);
You can then run the fake process and use the newly available assertions:
$result = Process::run('ls -la');
Process::assertRan(function ($process, $result) {
return $process->command == 'ls -la';
});
Process::assertRanTimes(function ($process, $result) {
return $process->command == 'ls -la';
}, times: 1);
Process::assertNotRan(function ($process, $result) {
return $process->command == 'cat foo';
});
Laravel 10 Deprecated Methods and Packages
Saying Goodbye to PHP 8.0
The new framework drops its support for PHP 8.0, so if you are still using PHP 8, you need to upgrade your app to Laravel 10 after updating the PHP version to PHP 8.1 or 8.2.
Removal of Deprecated Methods
The list of a few deprecations is as below. The codes using the deprecated method need to be rewritten with a new approach for getting the same result:
The getBaseQuery method, which has a base equivalent
The assertTimesSent() method
Functions and methods around dispatch now, deprecated to encourage developers to use dispatchSync, the only supported method for immediate dispatch
The MaintenanceModeException class
The mail fake’s Mail::failures method
Support for Predis 1 and DBAL 2
The Route::home method (deprecated in Laravel 9)
All related deprecations in doctrine/dbal since Laravel dropped support for version 2
The MocksApplicationServices trait
The $dates property (use $casts instead)
How to Upgrade Laravel 10
If you are keen to upgrade to Laravel 10, know that the core team has worked hard on the documentation to offer a clean and seamless upgrade guide. Check it out in the link.
Upgrades Made Simple with Laravel Shift
Also, do not miss to even check out Laravel Shift since Laravel 10 got released, as the shift will offer an automated and simple approach to upgrading your Laravel version.
Conclusion
Laravel 10 looks incredibly promising, and we’re eagerly anticipating the range of enhancements it brings to the world of PHP programming.
We hope you had a closer look at new features, fixes, and the latest on deprecated methods and packages that Laravel 10 offers, all conveniently detailed in this comprehensive guide.
For those seeking ways to optimize their Laravel application’s performance, choosing the best Laravel Development services might be a strategic move. While you choose to start on new Laravel projects, consider partnering with the industry’s top Laravel development company, equipped with a profound understanding of Laravel 10’s most competitive attributes. By availing of the finest Laravel development services, you can ensure seamless, secure, and high-speed functionality for your website, which can ultimately ensure heightened visibility and success.
Author
-
Sunil is a result-orientated Chief Technology Officer with over a decade of deep technical experience delivering solutions to startups, entrepreneurs, and enterprises across the globe. Have led large-scale projects in mobile and web applications using technologies such as React Native, Flutter, Laravel, MEAN and MERN stack development.
View all posts