Benjamin Crozat's blog

Everything PHP & Laravel

What's new in Laravel 10? A relevant list.

Benjamin Crozat's avatar. Benjamin Crozat, updated on — 4 minutes read

Let’s dive into every relevant new feature we know will be available in Laravel 10.

Laravel’s logo.

Dropped support for PHP 8.0

Some people are barely adopting PHP 8.0. Meanwhile, Laravel 10 will drop support for PHP 8.0, and that’s good.

Remember: big enterprise apps don’t need to be updated to the latest and greatest as soon as they’re released. Enterprise apps have paid clients or employees depending on them to do their work. They need to slowly but surely move forward by doing extensive testing.

See the pull request on GitHub: [10.x] Drop PHP 8.0

Dropped support for Predis v1

If you’re forcing the usage of Predis v1 in your project, you might want to upgrade to v2.

To see what changed in Predis v2, take a look at the changelog.

See the pull request on GitHub: [10.x] Drop Predis v1 support

In my opinion, instead of using Predis, you should consider using PHP’s native Redis extension, which is faster and could speed up your website if you have a lot of traffic.

dispatchNow() has been removed

dispatchNow() is a popular method in Laravel. It was deprecated in Laravel 9 in favor of dispatchSync(). Laravel 10 will remove it, so be sure to search and replace it in all of your projects. It may be a breaking change, but it’s an extremely easy fix.

See the pull request on GitHub: [10.x] Remove deprecated dispatchNow functionality

Many deprecated methods and properties have been removed

Releasing a major version also means the Laravel team can finally remove what’s been deprecated in Laravel 9. It also means you should carefully test any Laravel application you might want to migrate to version 10.

Here’s a list of all PRs taking care of that:

Laravel 10 uses invokable validation rules by default

In Laravel 9, invokable validation rules could be generated using the --invokable flag with the php artisan make:rule command. Starting from Laravel 10, you won’t need it anymore.

php artisan make:rule Uppercase

To remind you a bit of what invokable validation rules are, here’s what they look like:

namespace App\Rules;
 
use Illuminate\Contracts\Validation\InvokableRule;
 
class Uppercase implements InvokableRule
{
/**
* Run the validation rule.
*
* @param string $attribute
* @param mixed $value
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function __invoke($attribute, $value, $fail)
{
if (strtoupper($value) !== $value) {
$fail('The :attribute must be uppercase.');
}
}
}

The boilerplate code is considerably smaller and easier to understand. Thanks to Laravel 10, people will be less intimidated by the perspective of making custom validation rules.

That said, the old way of writing custom validation rules will still work.

See the pull request on GitHub: [10.x] Make invokable rules default

There’s more to come until February 2023. If you’re feeling awesome, follow me on Twitter and subscribe to my newsletter!