php artisan make:command Inspire
<?php namespace App\Console\Commands; use Illuminate\Console\Command; class Inspire extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'command:name'; /** * The console command description. * * @var string */ protected $description = 'Command description'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return int */ public function handle() { return 0; } }
Custom Console Color
It's very easy to define a custom console command with different colors and below are the available colors that you can print out to the terminal when running the custom console command.
// Default color $this->line('This is a line'); // Yellow collor $this->warn('This is a warning'); $this->comment('This is a comment'); // White text on red background $this->error('This is an error'); // Black text on cyan background $this->question('This is a question'); // Green color $this->info('This is some info');
<?php /* other codes ommited */ public function handle() { $this->info('You are running the Inspire command'); $this->comment('Performing some processing here'); $this->info('The command has been successfully executed'); return 0; }
More Colors Options
You can define more colors using the abbreviation of "bg" which stands for background and "fg" which stands for the foreground. The available colors that you can pick from any of the following colors: black, red, green, yellow, blue, magenta, cyan, white, default.
$this->line('<bg=black>Your message here</>'); $this->line('<fg=green>Your message here</>'); $this->line('<bg=red;fg=yellow>Your message here</>'); $this->line('<bg=red;fg=yellow>Your message here</>');
More Font Style Options
For the font style, you can use the following options: bold, underscore, blink, reverse, and conceal for the font style.
$this->line("<options=bold;fg=red>Your message here</>"); $this->line("<options=bold;fg=red>Your message here</>"); $this->line("<options=underscore;bg=cyan;fg=blue>Your message here</>");
Leave a reply