How to add information to the About command? The following article introduces how to add useful information to the Laravel About command. I hope it will be helpful to everyone!
The Laravel about command released in Laravel 9.21
provides an excellent overview of the important configuration of the application. Out of the box it lists environment details, the driver's cache status and configuration:
Another neat feature of the new about command is that packages can also Add useful information. For example, we introduced the Filament component in Laravel News; after the release of Laravel 9.21, Ryan Chandler initiated a pull request to add useful plugin details to Filament.
I think we'll see a lot of extension pack authors add some useful details to the about
command. But ultimately the hope is that users won't be overwhelmed with too much information, or perhaps extension pack developers will include configurable data in the about command.
After the introduction, how to add custom data to the "about" command?
You can do this using AboutCommand::add()
in the service provider's boot()
method.
In the following example, let's say I want my package or application to output a specific XDebug configuration value:
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', ]); }
Depending on your XDebug configuration, the above might look like this locally:
One thing to note when creating custom commands is that you should wrap the settings in fn() => ;
Arrow (anonymous) function to lazy load the output. For example:
'Client Port' => ini_get('xdebug.client_port'), 'Client Port' => fn() => ini_get('xdebug.client_port'),
I'm glad to see that the expansion pack author will add some useful information to this command!
原文地址:https://laravel-news.com/customize-laravel-about-command 译文地址:https://learnku.com/laravel/t/70189
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of Let's talk about how to add useful information to the About command in Laravel. For more information, please follow other related articles on the PHP Chinese website!