Hello Developers. As we know Laravel10 has been release on 14-feb-2023. Here we will know what is new features in laravel10.
Here we will check how we can install Laravel10.
composer create-project laravel/laravel laravel10-example
Some Features in Laravel10
Native type declarations
Now Laravel 10 uses native types and drops docblocks.
If we give you an example, then schedule()
method in app/Console/Kernel.php will look something like this in the Laravel skeleton:
/** * Define the application's command schedule. - * - * @param Illuminate\Console\Scheduling\Schedule $schedule - * @return void */ - protected function schedule($schedule) + protected function schedule(Schedule $schedule): void
Check another example
public function create({{ user }} $user): bool { // }
Artisan Command is More Interactive
See the below image
If i forget to pass the name while creating a model, you can do it with the new Artisan command.
php artisan make:model
Invokable Validation Rules by Default
Laravel 9 was offering invokable validation rules using –invokable flag with php artisan make:rule command. When a function is called on an object that has a __invoke method, PHP will automatically run the code inside of that method. See the below example-
php artisan make:rule UpperCase
See the Rules.
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 lowercase.'); } } }
Thanks for reading..
Read Also
Upgrade to Laravel10.0 From Laravel9.x
Install Latest Python on Linux Mint 21