Laravel 10 new features

Hamid Haghdoost - Feb 15 '23 - - Dev Community

Finally Laravel 10 is released. It requires PHP >= 8.1. Most of the features are added by the core Laravel team and not the other contributors and it seems that there is not a big changes compared previous version releases. Lets have a glance.

New Type Hinting Model

Nuno Maduro, creator of Pest has added new PHP style of type hinting and removed old way of dock-block in all stubs and maybe codebase. It seems that the change has not a sensible different for end-users :)

/**
* Display a listing of the resource.
*/
public function index(): Response
{
    // ...
}
Enter fullscreen mode Exit fullscreen mode

Features with Pennant

Another core member of Laravel, named Tim MacDonald has developed a new package named Pennant that makes it easy to publish specific features for specific users. consider a situation that you have added a new feature and you want to test it on a small chunk of users. the package has introduced a convenient way for that.

use Laravel\Pennant\Feature;
use Illuminate\Support\Lottery;

Feature::define('new-onboarding-flow', function () {
    return Lottery::odds(1, 10);
});
Enter fullscreen mode Exit fullscreen mode

Process Interaction in a simple way

This feature is a little bit funny. I have experience working with the commands line exec which we can run a program in OS's shell with PHP like ls -a. With this new feature, you can run this kind of command with a better coding interface:

use Illuminate\Support\Facades\Process;

$result = Process::run('ls -la');

return $result->output();
Enter fullscreen mode Exit fullscreen mode

Profile tests

If your tests take too much to be ended (like me:)) try this feature. It profiles your tests and reports the execution time which makes it easy to find slow tests.

php artisan test --profile
Enter fullscreen mode Exit fullscreen mode

Image description

Use Pest for testing

If you prefer the Pest PHP testing format for writing your tests, Now it is built in on Laravel and you can use it easily.

Command CLI prompts

This feature prompts the user to complete the command if it was not complete. For example, if you run a command like this:

php artisan make:controller
Enter fullscreen mode Exit fullscreen mode

It asks you the name of controller. We can accept it from Jess :)

Better Horizon and Telescope

Finally if you are a fan of one of the above tools, there is a little bit face lift on them.

Overall, I think the changes were not big but that is the open-source world and we have to thank the contributors for their efforts. If you want a new thing, go and write it :) Have a good time.

. . . . . . . . . . .