What’re New features and changes in Laravel 10 | Every Developer Should Know.
Laravel 10 was released on February 14, 2023, and currently is the latest version. After this release, it comes with new features and changes. In this tutorial, I will describe major features and changes in Laravel 10.
The new features and changes in Laravel 10 are as follows:
- End of support for PHP 8.0
- Compatible with PHP 8.2.
- Predis Version Upgrade.
- Improved routing speed and reliability.
- Process layer for Laravel
use Illuminate\Support\Facades\Process;
$result = Process::run('ls -la');
return $result->output();
6. Artisan Become More Interactive.
php artisan make:model
After running this command it does not give an error, it will 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
7. The new String Password helper
Str::password
the method can generate a secure, random password of a given length. The password will consist of a combination of letters, numbers, symbols, and spaces. By default, passwords are 32 characters long.
Here is an example:
use Illuminate\Support\Str;
$password = Str::password();
// 'B78qwuar-#V_LN,$%_dfdsrV4ndfd~fdfds/-_6sdfs'
$password = Str::password(12);
// 'Jo2vEA4>#V|dsadsa'
8. Use of 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 don’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.');
}
}
}
9. Native Type Declarations in Laravel 10 Skeleton.
10. Support for Native Column Modification.
11. 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 blog --dev
or
composer create-project --prefer-dist laravel/laravel blog --dev
12. dispatchNow() is Replaced by dispatchSync().