Laravel0Add Useful Info to the Laravel About Command

[ad_1]

The Laravel about command released in Laravel 9.21 provides an excellent overview of important configurations for your application. Out of the box, it lists environment details, cache status, and configured drivers:

Another neat feature of the new about command is the ability for packages to add helpful information too. For example, we’ve covered Filament components here on Laravel News; after the release of Laravel 9.21, Ryan Chandler opened a pull request to add useful plugin details to Filament.

I think we’ll see a lot of package authors add helpful details to the about command. Hopefully, the end-user doesn’t get overwhelmed with too much info, or perhaps package developers make the inclusion of data in the about command configurable.

With that intro out of the way, how would you add custom data to the about command?

You can do so in a service provider, using the AboutCommand::add() method within the service provider’s boot() method.

In the following example, let’s say I wanted my package or application to output specific XDebug configuration values:

use Illuminate\Foundation\Console\AboutCommand;

 

// ...

 

public function boot()

{

AboutCommand::add('XDebug Settings', [

'Client Port' => fn() => ini_get('xdebug.client_port'),

'Client Host' => fn() => ini_get('xdebug.client_host'),

'Start With Request' => fn() => ini_get('xdebug.start_with_request'),

'Max Nesting Level' => fn() => ini_get('xdebug.max_nesting_level'),

'Mode' => fn() => ini_get('xdebug.mode'),

'Output Dir' => fn() => ini_get('xdebug.output_dir'),

'Log' => fn() => !empty(ini_get('xdebug.log')) ? ini_get('xdebug.log') : 'No Value',

]);

}

The above might look like the following locally, depending on your XDebug configuration:

Lazy Loading

One thing to note when creating custom about commands is that you should lazy load the output by wrapping the settings in an fn() => arrow function. For example:

-'Client Port' => ini_get('xdebug.client_port'),

+'Client Port' => fn() => ini_get('xdebug.client_port'),

I am excited to see what helpful information package authors start adding to this command!

[ad_2]

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *