Cachet 3.x is under development. Learn more.

Extending Laravel’s "about" Command

Last year, I contributed a new about command to the Laravel framework. This command prints out information about your application:

$ php artisan about

Environment .........................................................  
Application Name .............................................. Forge  
Laravel Version .............................................. 9.51.0  
PHP Version ................................................... 8.2.1  
Composer Version .............................................. 2.5.1  
Environment ................................................... local  
Debug Mode .................................................. ENABLED  
URL ...................................................... forge.test  
Maintenance Mode ................................................ OFF  

Cache ...............................................................  
Config ................................................... NOT CACHED  
Events ................................................... NOT CACHED  
Routes ................................................... NOT CACHED  
Views ........................................................ CACHED  

Drivers .............................................................  
Broadcasting ................................................. pusher  
Cache .......................................................... file  
Database ...................................................... mysql  
Logs .......................................................... daily  
Mail ........................................................... smtp  
Queue ......................................................... redis  
Session .................................................... database  

Extra things you can do with this command

Using the --only option, you may specify a comma-separated list of sections to display:

$ php artisan about --only=cache,drivers

Cache ...............................................................  
Config ................................................... NOT CACHED  
Events ................................................... NOT CACHED  
Routes ................................................... NOT CACHED  
Views ........................................................ CACHED  

Drivers .............................................................  
Broadcasting ................................................. pusher  
Cache .......................................................... file  
Database ...................................................... mysql  
Logs .......................................................... daily  
Mail ........................................................... smtp  
Queue ......................................................... redis  
Session .................................................... database 

Of course, you can also get the information in JSON format using the --json option:

$ php artisan about --json

{"environment":{"application_name":"Forge","laravel_version":"9.51.0","php_version":"8.2.1","composer_version":"2.5.1","environment":"local","debug_mode":"ENABLED","url":"forge.test","maintenance_mode":"OFF"},"cache":{"config":"NOT CACHED","events":"NOT CACHED","routes":"NOT CACHED","views":"CACHED"},"drivers":{"broadcasting":"pusher","cache":"file","database":"mysql","logs":"daily","mail":"smtp","queue":"redis","session":"database"}}

Appending your own information

What you may not know is that you can also add your own application or package information into the command’s output. For package developers, this allows you to share additional information such as drivers, versions etc. and for application developers, this allows you to add application-specific information.

To share information with the about command, you need to update your service provider’s boot method:

use Illuminate\Foundation\Console\AboutCommand;
 
/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    AboutCommand::add('My Package', fn () => ['Version' => '1.0.0']);
}

Yes, that’s all it takes.

Firstly, we pass through the "section" name. This is how the command will separate the output and of course, we can add to the default sections by passing the same names.

$ php artisan about --only=my_package

My Package ..........................................................  
Version ....................................................... 1.0.0

Notice how we can also specify my_package in the --only option?

Next, we're passing a callable that returns an array of key/value pairs for information add. Alternatively, we can pass an array of data, However, when passing a callable, Laravel will only evaluate the information when it executes the about command. This is a performance optimisation to prevent applications from always loading the information, even when it’s not needed.

Some packages are already extending the about command: