How can I add a badge in output message command of laravel artisan?

68 Views Asked by At

I am creating a laravel artisan command and work fine, but I want the output like the bellow image someone know the solution for this question? laravel artisan command output sample

I want add a badge like a native artisan command.

1

There are 1 best solutions below

0
Tim Lewis On

This isn't in the documentation, but the way the base Artisan commands do this is via $this->components->info(...). This seems to work in a generated Console Command, via extends Command:

<?php

namespace App\Commands;

use Illuminate\Console\Command;

class ExampleCommand extends Command {
  protected $signature = 'example';

  public function handle() {
    $this->components->info('Hello World.');
  } 
}

Running this command via php artisan example generates the following output:

INFO Hello World.

Screenshot:

enter image description here

Example in the Framework Codebase:

https://github.com/laravel/framework/blob/10.x/src/Illuminate/Console/GeneratorCommand.php#L194