I was curious, I\'m using Laravel and Artisan for my migrations. Is there a method to output information to the console? I can\'t seem to find any information on this. For examp
Talking about Laravel 5 (you can check the version you have with php artisan --version
), the Migration base-class has no printing method.
A simple echo
will do the work, However, if you want, you can extend it and add this functionality:
abstract class MyMigration extends Migration
{
// colors for console echo
protected const COLOR_RED = 'COLOR_RED';
protected const COLOR_GREEN = 'COLOR_GREEN';
protected const COLOR_YELLOW = 'COLOR_YELLOW';
protected function logMessage($str, String $color = null)
{
switch ($color) {
case self::COLOR_RED:
$str = "\033[01;31m$str\033[0m";
break;
case self::COLOR_GREEN:
$str = "\033[01;32m$str\033[0m";
break;
case self::COLOR_YELLOW:
$str = "\033[01;33m$str\033[0m";
break;
echo $str . PHP_EOL;
}
}
}
and then simply call it with your message:
$this->logMessage("Your message", self::COLOR_RED );