98 words, 1 min read

If you want to output a text in the console using Laravel and make it a clickable hyperlink, you can easily do it like this:

namespace App\Console\Commands;
use Illuminate\Console\Command;
class SampleCommand extends Command
{
protected $signature = 'sample';
protected $description = 'Prints a text with a hyperlink to the console';
public function handle(): int
{
$this->info('<href=https://www.yellowduck.be>hello world</>');
return self::SUCCESS;
}
}

You can also use it to color the output by adding:

$this->info('<bg=yellow;fg=red;href=https://www.yellowduck.be>hello world</>');

The syntax is really simple:

  • bg: background color
  • fg: foreground color
  • href: a hyperlink

The Symfony module behind this is what makes this work.