Home > PHP Framework > Laravel > body text

Let's talk about how to add useful information to the About command in Laravel

青灯夜游
Release: 2023-01-17 20:21:01
forward
1886 people have browsed it

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!

Let's talk about how to add useful information to the About command in Laravel

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',
    ]);
}
Copy after login

Depending on your XDebug configuration, the above might look like this locally:

Lazy Loading

One thing to note when creating custom commands is that you should wrap the settings in fn() =&gt ; 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'),
Copy after login

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
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template