If you are about to start Laravel development, this post is your Holy grail! 

Developers’ beloved and friendly PHP framework has recently achieved some new features and improvements and released a Laravel 9.21 with a fresh look for Artisan. The command line interface exists at the root of the app. It provides time and labor-saving commands to build efficient applications.

In the Laravel 9.21 update, the Artisan CLI has received a makeover with the contribution of Nuno Maduro, who also stated, “Nearly all the built-in Artisan commands have been reimagined to deliver a better experience.”

Not only this, many software engineers have contributed and made Artisan CLI even more valuable by introducing rewarding features to boost the development process.

Now, this Laravel 9.21 release note has made all the Laravel developers, including us, as keen as mustard to learn more about Artisan. So, let us dig into Laravel 9.21 new features and improvements right away!

What new Laravel 9.21

What new Laravel 9.21 Release Note brought?

Makeover of Artisan

Nuno has taken the pull request (#43065) very seriously, which we can see in the whole new look of Artisan. If you compare the old and new versions side-by-side, you will notice how the latest one looks cleaner and more organized. 

However, the main objective of this PR is to improve the Artisan output. All the previous command calls to $this->info, $this-> warn, and more have been replaced with $this->components->info, so on. It is a common change made to ensure only internal commands of the framework get affected by the new output. 

Noteworthy, the new components mutate the given information in terms of punctuation, relative paths instead of absolute paths, and more. Besides these, they have refreshed over 100 commands. Yet, it won’t affect commands like completion, help, List, tinker, serve, and Laravel packages such as Horizon or Telescope. As well as error command from Symfony, such as invalid arguments, etc. 

Artisan About command

To make developers’ lives even easier, James Brooks has introduced a brand new command, i.e.,  About. It gives a general overview of the entire application. Basically, it displays output about the Laravel system environment, including debug mode, PHP version, cache statuses, etc., as well as the configuration of the user’s application.

About has its own API that allows applications and packages to push data into already created sections or create a new one with its own data:

use Illuminate\Foundation\Console\AboutCommand;

AboutCommand::add(‘Laravel Vapor’, ‘Vapor Runtime’, ‘1.0.0’);

To add multiple items:

AboutCommand::add(‘Environment’, [

    ‘Laravel Cashier’ => ‘Stripe’,

    ‘Laravel Nova’ => ‘4.0.0’

]);

The new command seems to be great for package maintainers. Because it gives insights into debugging info from the users, leading to fixing issues.

Artisan model show command

Added by Jess Archer, ‘model:show’ is another valuable Artisan command in the Laravel 9.21 update. The command gathers information from the database as well as Eloquent and displays an end-to-end overview of your model.

model:show command is more helpful when the application grows and requires multiple migrations. Because along with database columns, it also displays virtual attributes like accessories and attributes to unmatched columns in the database.

Among other specialties, there is also a –json flag to get the output in a JSON format. That said, you can use this to collect information and use it somewhere else easily.

Laravel 9.21 Release Note

Added a whenCounted method to JsonResource

Steve Bauman worked and added whenCounted method to the JSON resource. It will allow you to include attributes in a response conditionally when a relation to count is set on the model. 

It works pretty similarly to whenLoaded method. However, there is an exception. The value of the retrieved count attribute will be passed into the $value callback (if one is provided).

Steve has also added another method called hasAttribute. It can quickly determine if the given attribute exists inside the model’s raw $attributes array. Consequently, you won’t need to fetch all model attributes to see if it exists.

Some notable improvements come with Laravel 9.21.0 update

  • #43181 PR solves the issue of assertDatabaseHas test fails that earlier showed similar or found results, which was challenging to see by those using multibyte languages. 
  • ValidationException outlines only when using strings #43177.
  • Clear Facade resolvedInstances in queue worker resetScope callback #43215.
  • Improves queue:work command when the job class code contains a $this->fail() and when jobs a requeued to be retried later #43252.
  • Resolving PR #43278, they improved the protection against “Integrity constraint violation: 1052 Column’ id’ in where clause is ambiguous” error while applying global scope to a user model.
  •  #43259 PR adds the special lock flag readpast for the sqlsrv driver. Until now there was no particular handling for the sqlsrv database driver even though it supports similar features and deadlocks were a frequent issue. But not anymore!

Wrapping Up!

Laravel 9.21.0 is proof that the framework ain’t going to stop making PHP development even simpler for beginners and expert developers alike. Not only Artisan, Eloquent ORM, Template Engine, Modularity, Security, and its lightweight characteristics are also a plus point to choosing Laravel.

So, if you belong to a business unit and researching the best PHP framework to choose, hire Laravel developers and kick off. You will get ample time to focus on what matters for your brand while the framework will intensify your digital presence.

Looking for professional Laravel developers?