10 Useful Features of Laravel 10 Everyone Should Know About
On February 7, 2023, Laravel, a well-known PHP web application framework, released its newest version, Laravel 10. This version includes a host of exciting new features and upgrades.
The Laravel community was thrilled about the launch because Laravel used to release upgrades twice a year — every six months. But following the release of Laravel 9, its founder Taylor Otwell made the decision to release a single version of Laravel every year with significant updates.
And with its most recent updates, Laravel 10, a top framework for building web applications, is ready to rock the development industry.
So, whether you’re an experienced Laravel developer or just starting out, this blog will offer you a thorough overview of what’s new in Laravel 10 and how it can assist you in creating better, more efficient web apps.
Prepare yourself to explore Laravel 10 and all of its new features.
Top 10 Features of Laravel 10 That Has Taken World By Storm
1. Dropped Support for PHP 8.0
PHP 8.1 is the minimal PHP version required in Laravel 10. According to a GitHub comparison of the Laravel 9 branch and the framework’s main branch, Laravel 10 introduces some PHP 8.1 features, such as readonly properties and array_is_list.
2. Compatible with PHP 8.2
PHP 8.2 was launched on December 8, 2022, just two months before the scheduled release of Laravel 10. However, this shouldn’t prevent you from using PHP 8.2 features because Laravel 10 is already prepared for PHP 8.2 and shouldn’t require any more work.
In fact, PHP 8.2 is supported by the entire Laravel ecosystem, including Forge, Vapor, and Envoyer. PHP 8.2 is even compatible with Laravel 9.
3. Predis Version Upgrade
Predis is a powerful Redis client for PHP that may assist you in getting the most out of caching to deliver a wonderful user experience. Laravel previously supported versions 1 and 2, but Predis 1 is no longer supported as of Laravel 10.
Check out the changelog to learn what was altered in Predis v2.
Instead of Predis, I believe you should consider utilizing PHP’s native Redis extension, which is faster and potentially speeds up your website if you have a high traffic volume.
4. Artisan Become More Interactive
With Laravel 10, Artisan will be more interactive. Consider a scenario where you asked it to generate a model but omitted the name:
php artisan make:model
Instead of giving an error, it will merely ask you for the model’s name and whether you want to build a migration, factory, etc. This will make the development job much easier!
php artisan make:model
What should the model be named?
❯ Post
Would you like any of the following? [none]
none ......................................................................................... 0
all .......................................................................................... 1
factory ...................................................................................... 2
form requests ................................................................................ 3
migration .................................................................................... 4
policy ....................................................................................... 5
resource controller .......................................................................... 6
seed ......................................................................................... 7
5. Invokable Validation Rules Are the Default
If you want to create an invokable validation rule in Laravel 9, you must add the — invokable flag after the artisan command. Since all Laravel 10 rules can be invoked by default, this is no longer necessary. Therefore, to create a new invokable rule in Laravel 10, you can issue the following command:
php artisan make:rule Uppercase
When you give the above command, you can expect to see the following result:
# Laravel 9 creates a rule class that implements the
# Illuminate\Contracts\Validation\Rule interface
artisan make:rule Uppercase
# Laravel 9 flag to create an invokable and implicit rule
artisan make:rule Uppercase --invokable
artisan make:rule Uppercase --invokable --implicit
# Laravel 10 creates an invokable rule by default
artisan make:rule Uppercase
# Laravel 10 implicit rule
artisan make:rule Uppercase --implicit
6. Native Type Declarations in Laravel 10 Skeleton
Previously, Laravel used DocBlocks in its skeleton code to describe what a piece of code does and what kinds of parameters or answers to anticipate. However, this will alter with the introduction of native-type declarations in Laravel 10.
The easiest way to describe this change is with a straightforward illustration. In place of a function like this:
/**
* Determine whether the user can create models.
*
* @param \{{ namespacedUserModel }} $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function create({{ user }} $user)
{
//
}
It will appear like this in its place:
/**
* Determine whether the user can create models.
*/
public function create({{ user }} $user): bool
{
//
}
This modification is solely for the advantage of the developer experience, as IDEs will recognize the shape of the intended parameter and response. When using PHP’s native types is not an option, it will provide better type clarity. As a result, it will assist code editors in performing better with auto-complete functions.
7. Support for Native Column Modification
With Laravel 10, a new functionality will be available that aims to do away with the need for doctrine/dbal when using change() to alter columns. This feature will allow developers to utilize the change() function to modify columns in MySQL, PostgreSQL, and SQL Server without needing additional packages. This is a substantial and risky move, but we believe it is valuable because it eliminates the need for an additional package.
And if you already have Doctrine DBAL installed and have several database connections. In that scenario, call Schema::useNativeSchemaOperationsIfPossible()function within the boot method in App\Providers\AppServiceProvider to be able to use native schema operations and to utilize native operations before depending on the package (SQLite, for instance, does not yet support this):
use Illuminate\Support\Facades\Schema;
…
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Schema::useNativeSchemaOperationsIfPossible();
}
}
8. Deprecations from Laravel 9
In Laravel 10, methods tagged as deprecated in Laravel 9 will no longer be used. We may anticipate that the release upgrading guide will describe all the deprecated techniques, probable effect analysis, and how to upgrade shortly after the release.
Currently, the `master` branch of the Laravel framework has the following deprecations when compared to the `9.x` branch:
- Remove diverse deprecations Pull Request #41136
- Remove deprecated dates property in Pull Request #42587
- Remove `handleDeprecation` method in Pull Request #42590
- Remove deprecated `assertTimesSent` method Pull Request #42592
- Remove deprecated `ScheduleListCommand`’s `$defaultName` property 419471e
- Remove deprecated `Route::home` method Pull Request #42614
- Remove deprecated `dispatchNow` functionality Pull Request #42591
Source: Laravel News
9. Testing Laravel 10
If you want to start testing Laravel 10 right away, use the ` — dev` flag to install it in a new project:
laravel new <your-project-name> --dev
10. Discontinued dispatchNow ()
Yes, Laravel 10 no longer includes the `dispatchNow` method. Previously, the `dispatchNow` method was used to dispatch a job that would be run immediately, bypassing the queue mechanism.
However, with Laravel 10, this approach has been abandoned, and using the sync queue driver is now advised if you want to do a job immediately. This is accomplished by setting the queue attribute of your job to sync.
Here is an illustration of how to utilize Laravel 10’s sync queue driver to start a job immediately:
// in your job class
public $queue = 'sync';
// in your controller or other code
dispatch(new YourJob($data))->onQueue('sync');
By utilizing the sync queue driver, you can guarantee that your job will be carried out instantly without first being added to the queue system. This can come in handy when you need to complete a task immediately and can’t wait for the queue to process it.
Should You Switch to Laravel 10?
It’s crucial to remember that we don’t necessarily have to update the Laravel version of our application to the most recent version as soon as a new version is available.
Since Laravel is an open-source framework, we automatically own the framework’s codebase each time we install a new Laravel instance on our computer. This implies that our app will continue to function even if the framework version it uses is no longer maintained; we will merely need to maintain it ourselves.
It is, therefore, often advised to give application stability precedence over framework upgrades.
To put it briefly, you should think about upgrading to Laravel 10 when:
- The application is stable in its existing version and works flawlessly.
- The updated version either adds a feature that your application needs or resolves a problem it was having.
- The application will be thoroughly tested before the upgrade changes are pushed into production.
Conclusion
So, those are the most recent features of Laravel 10. You can also visit the Official Release Page for additional details and updates on the releases.
Laravel is a well-known open-source framework that has long dominated the PHP framework field due to its powerful and beautiful syntax. The most recent version, Laravel 10, will make it simple to create online applications.
In that scenario, if you want a reliable partner for designing your web application project, you can take help from any top Laravel Development Company.
Windzoon has a team of skilled developers who have completed around 100 projects and can assist you in developing user-friendly web apps with robust features using cutting-edge technology. Contact us today to get a quote.